英文:
Encrypt and Decrypt AES with Golang and Ruby
问题
我正在努力让两个安全系统通过一种共同的加密方案进行通信。我选择了AES作为加密标准,因为它似乎是一种安全的标准,但我并不固执于它,只要我能够进行双向加密即可。
这里有一个简化的示例,使用Go语言和Ruby语言编写的源代码,可以在命令行中运行并查看它们之间的区别。我输出字节码以便进行更容易的直接比较。
我在两个系统中都使用了128位的CFB模式,并且它们似乎都没有使用填充。非常感谢任何帮助!
英文:
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
得分: 2
你在 Ruby 代码中传递了错误的密钥大小。应该是192位(因为key.size
为24字节,等于192位)。
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: [155 79 127 80 31 163 142 111 13 211 221 163 219 248]
英文:
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]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论