【问题标题】:How is write PHP mcrypt_ecb decrypt in Ruby?如何在 Ruby 中编写 PHP mcrypt_ecb 解密?
【发布时间】:2012-04-22 12:00:16
【问题描述】:
public static function decryptSessionByDES($str,$key_str){
  $decoded =base64_decode($str);
  $iv = substr($key_str, 0, mcrypt_get_iv_size(MCRYPT_3DES,MCRYPT_MODE_ECB));
  return trim(mcrypt_ecb(MCRYPT_3DES, $key_str, $decoded, MCRYPT_DECRYPT, $iv));
}

如何在 Ruby 中隐藏这段代码?

【问题讨论】:

  • 在您的问题中包含示例输入和预期的相应输出可能会有所帮助。

标签: php ruby encryption mcrypt


【解决方案1】:

我已经解决了:

这是 libmcrypt 中的 gem 库:https://github.com/kingpong/ruby-mcrypt

require "mcrypt"
class Crypt
  def self.decrypt_session_by_des(str, key_str)
    str_decoded = Base64.decode64(str)
    mc = Mcrypt.new(:des,:ecb)
    mc.padding = :pkcs
    mc.key = key_str
    mc.decrypt(str_decoded)
  end
end

和其他解密或加密你可以在 ruby​​-mcrypt 中看到测试用例: https://github.com/kingpong/ruby-mcrypt/blob/master/test/test_reciprocity.rb

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-07
    • 2015-10-07
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    相关资源
    最近更新 更多