Encrypting/decrypting 3DES in Ruby

后端 未结 1 377
太阳男子
太阳男子 2021-01-13 08:34

I have a key.bin file which content is something along the lines of:

-12, 110, 93, 14, -48, ...

This is being used by a service to decrypt

相关标签:
1条回答
  • 2021-01-13 09:03

    Got it working!

    Here's how:

    Decryption

    def read_key(key_file)
      File.read(key_file).split(',').map { |x| x.to_i }.pack('c*')
    end
    des = OpenSSL::Cipher::Cipher.new('des-ede3')
    des.decrypt
    des.key = read_key('key.bin')
    
    result = des.update(decoded) + des.final
    

    Encryption

    def read_key(key_file)
      File.read(key_file).split(',').map { |x| x.to_i }.pack('c*')
    end
    des2 = OpenSSL::Cipher::Cipher.new('des-ede3')
    des2.encrypt
    des2.key = read_key('key.bin')
    
    result = des2.update(result) + des2.final
    puts Base64.encode64(result)
    
    0 讨论(0)
提交回复
热议问题