解密代码,从ruby到js

Decrypt code , from ruby to js

本文关键字:js ruby 代码 解密      更新时间:2023-09-26

有人知道如何将下面的ruby脚本翻译成javascript吗?

source = ENCRYPTED_STRING
cipher = OpenSSL::Cipher::Cipher.new('AES-128-ECB')
cipher.decrypt
cipher.key = ['SECRET'].pack('H*')
decoded = Base64.decode64(source)
decrypted = cipher.update(decoded) + cipher.final

我假设您想使用"SECRET"作为密码短语加密字符串。

下面是一个使用crypto-js的例子:
source = ENCRYPTED_STRING
var encrypted = CryptoJS.AES.encrypt(source, "SECRET");

http://yijiebuyi.com/blog/13e2ae33082ac12ba4946b033be04bb5.html

问题解决了。 function decryption(data, key) { var iv = ""; var clearEncoding = 'utf8'; var cipherEncoding = 'base64'; var cipherChunks = []; var decipher = crypto.createDecipheriv('aes-128-ecb', key, iv); decipher.setAutoPadding(true); cipherChunks.push(decipher.update(data, cipherEncoding, clearEncoding)); cipherChunks.push(decipher.final(clearEncoding)); return cipherChunks.join(''); }