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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料