feat(string coder) add some algorithms

This commit is contained in:
lumither committed 2024-10-15 21:12:36 -07:00
1 parent efdea9872f
commit 57a0b66b84
3 files changed
+26 -32

No files matched your search

+15
View File
@@ -1,4 +1,7 @@
import { enc, MD5, SHA1, SHA256, SHA512 } from 'crypto-js';
import basex from 'base-x';
const BASE58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
export const hashAlgorithms = {
'SHA-1': (input: string) => {
@@ -16,6 +19,9 @@ export const hashAlgorithms = {
};
export const encodeAlgorithms = {
'Base58': (input: string) => {
return basex(BASE58).encode(Buffer.from(input));
},
'Base64': (input: string) => {
const wordArray = enc.Utf8.parse(input);
return enc.Base64.stringify(wordArray);
@@ -25,10 +31,16 @@ export const encodeAlgorithms = {
},
'URI Component': (input: string) => {
return encodeURIComponent(input).toString();
},
'Hex': (input: string) => {
return enc.Hex.stringify(enc.Utf8.parse(input));
}
};
export const decodeAlgorithms = {
'Base58': (input: string) => {
return Buffer.from(basex(BASE58).decode(input)).toString();
},
'Base64': (input: string) => {
return enc.Base64.parse(input).toString(enc.Utf8);
},
@@ -37,6 +49,9 @@ export const decodeAlgorithms = {
},
'URI Component': (input: string) => {
return decodeURIComponent(input).toString();
},
'Hex': (input: string) => {
return enc.Hex.parse(input).toString(enc.Utf8);
}
};