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中转换此代码?
答案 0 :(得分:1)
我解决了这个问题:
这是libmcrypt中的宝石基础: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