1
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でこのコードを変換するには?

4

1 に答える 1

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

于 2012-04-11T01:54:33.243 に答える