dongzhidian3538 2014-03-23 13:51
浏览 65
已采纳

使用Golang和Ruby加密和解密AES

I'm working on making two secure systems talk via a common encryption scheme. I picked AES as it seems a secure standard, but I'm not married to it, so long as I have two way encryption.

Here is the Go source and Ruby source simplified down to a really clear example to run from command line and see the differences. I'm outputting bytecode for easier literal comparison.

I'm using 128 bit CFB in both, and neither of them appear to have padding, any help is greatly appreciated!

  • 写回答

1条回答 默认 最新

  • dou47278 2014-03-23 14:40
    关注

    You passed wrong key size in Ruby code. It should be 192. (because key.size is 24 bytes == 192 bits)

    cipher = OpenSSL::Cipher::AES.new(192, :CFB)
    cipher.encrypt
    cipher.key = key
    cipher.iv = iv
    encrypted = cipher.update(input) + cipher.final()
    puts "Output:     [" + encrypted.bytes.join(" ") + "]"
    

    output:

    Output:     [155 79 127 80 31 163 142 111 13 211 221 163 219 248]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?