feat: use aes lib foe encryption
This commit is contained in:
@@ -229,6 +229,37 @@ async function encryptMessage(key, message) {
|
||||
return new Uint8Array(ciphertext)
|
||||
}
|
||||
|
||||
async function encryptMessage2(key, message) {
|
||||
// The iv must never be reused with a given key.
|
||||
// iv = window.crypto.getRandomValues(new Uint8Array(16));
|
||||
while (message.length % 16 !== 0) message += ' '
|
||||
const encodedMessage = asciiToUint8Array(message)
|
||||
iv = new Uint8Array([
|
||||
0x00,
|
||||
0x01,
|
||||
0x02,
|
||||
0x03,
|
||||
0x04,
|
||||
0x05,
|
||||
0x06,
|
||||
0x07,
|
||||
0x08,
|
||||
0x09,
|
||||
0x0a,
|
||||
0x0b,
|
||||
0x0c,
|
||||
0x0d,
|
||||
0x0e,
|
||||
0x0f
|
||||
])
|
||||
|
||||
const aesCbc = new aesjs.ModeOfOperation.cbc(key, iv)
|
||||
const encryptedBytes = aesCbc.encrypt(encodedMessage)
|
||||
|
||||
console.log('### #####################################')
|
||||
return encryptedBytes
|
||||
}
|
||||
|
||||
async function decryptMessage(key, ciphertext) {
|
||||
iv = new Uint8Array([
|
||||
0x00,
|
||||
|
||||
Reference in New Issue
Block a user