【问题标题】:Decrypt code , from ruby to js解密代码,从 ruby​​ 到 js
【发布时间】:2015-12-18 02:03:10
【问题描述】:

有人知道如何将下面的 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

【问题讨论】:

  • 找到一个进行 AES 加密的库。这将是开始并遵循它的指示。
  • Google 是你的朋友。

标签: javascript ruby encryption crypt


【解决方案1】:

我假设您想使用“SECRET”作为密码来加密字符串。

这是一个使用crypto-js的例子:

source = ENCRYPTED_STRING
var encrypted = CryptoJS.AES.encrypt(source, "SECRET");

【讨论】:

    【解决方案2】:

    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(''); }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-12
      • 1970-01-01
      • 2020-11-25
      • 2018-01-13
      • 1970-01-01
      • 2010-10-11
      • 2012-05-11
      • 1970-01-01
      相关资源
      最近更新 更多