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

报告相同问题?

悬赏问题

  • ¥15 SQLServer怎么录入下标
  • ¥100 无网格伽辽金方法研究裂纹扩展的程序
  • ¥15 错误于library(org.Hs.eg.db): 不存在叫‘org.Hs.eg.db’这个名称的程序包,如何解决?
  • ¥60 求一个图片处理程序,要求将图像大小跟现实生活中的大小按比例联系起来的
  • ¥50 求一位精通京东相关开发的专家
  • ¥100 求懂行的大ge给小di解答下!
  • ¥15 pcl运行在qt msvc2019环境运行效率低于visual studio 2019
  • ¥15 MAUI,Zxing扫码,华为手机没反应。可提高悬赏
  • ¥15 python运行报错 ModuleNotFoundError: No module named 'torch'
  • ¥100 华为手机私有App后台保活