complete V1
This commit is contained in:
parent
da5b74b5f1
commit
d0c95f579e
|
@ -11,6 +11,15 @@ export async function bufferToBase64(buffer: BufferSource) {
|
|||
return base64url.slice(base64url.indexOf(',') + 1);
|
||||
}
|
||||
|
||||
export function base64ToArrayBuffer(base64: string) {
|
||||
var binaryString = atob(base64);
|
||||
var bytes = new Uint8Array(binaryString.length);
|
||||
for (var i = 0; i < binaryString.length; i++) {
|
||||
bytes[i] = binaryString.charCodeAt(i);
|
||||
}
|
||||
return bytes.buffer;
|
||||
}
|
||||
|
||||
export class AES256 {
|
||||
static async str2key(key: string): Promise<CryptoKey> {
|
||||
if (key.length > 32)
|
||||
|
@ -56,9 +65,22 @@ export class V1 {
|
|||
}
|
||||
|
||||
return {
|
||||
data: await bufferToBase64(await AES256.encodeStr(scrambled, this.aes256secret))
|
||||
data: await bufferToBase64(await AES256.encodeStr(scrambled, this.aes256secret)),
|
||||
made_at: Date.now()
|
||||
}
|
||||
}
|
||||
|
||||
static async decode(data: { data: string }): Promise<string> {
|
||||
const encrypted = base64ToArrayBuffer(data.data);
|
||||
const scrambled = await AES256.decodeToStr(encrypted, this.aes256secret);
|
||||
let unscrambled = '';
|
||||
for (let i = 0; i != scrambled.length; i++) {
|
||||
if (i % 2 == 1) {
|
||||
unscrambled += scrambled[i];
|
||||
}
|
||||
}
|
||||
return unscrambled;
|
||||
}
|
||||
}
|
||||
|
||||
export function encode(word: string) {
|
||||
|
|
Loading…
Reference in New Issue