1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.base64ToBuffer = exports.bufferToBase64 = exports.base64ToString = exports.stringToBase64 = exports.hashAsBuffer = exports.hash = exports.md5AsBuffer = exports.md5 = void 0;
|
4 | const crypto = require("crypto");
|
5 | function md5(s) {
|
6 | return hash(s, 'md5');
|
7 | }
|
8 | exports.md5 = md5;
|
9 | function md5AsBuffer(s) {
|
10 | return hashAsBuffer(s, 'md5');
|
11 | }
|
12 | exports.md5AsBuffer = md5AsBuffer;
|
13 | function hash(s, algorithm) {
|
14 | return crypto.createHash(algorithm).update(s).digest('hex');
|
15 | }
|
16 | exports.hash = hash;
|
17 | function hashAsBuffer(s, algorithm) {
|
18 | return crypto.createHash(algorithm).update(s).digest();
|
19 | }
|
20 | exports.hashAsBuffer = hashAsBuffer;
|
21 | function stringToBase64(s) {
|
22 | return Buffer.from(s, 'utf8').toString('base64');
|
23 | }
|
24 | exports.stringToBase64 = stringToBase64;
|
25 | function base64ToString(strBase64) {
|
26 | return Buffer.from(strBase64, 'base64').toString('utf8');
|
27 | }
|
28 | exports.base64ToString = base64ToString;
|
29 | function bufferToBase64(b) {
|
30 | return b.toString('base64');
|
31 | }
|
32 | exports.bufferToBase64 = bufferToBase64;
|
33 | function base64ToBuffer(strBase64) {
|
34 | return Buffer.from(strBase64, 'base64');
|
35 | }
|
36 | exports.base64ToBuffer = base64ToBuffer;
|