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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题