libgcrypt AES 返回 ascii 密文?
嘿,我正在开发一个 JNI 共享库,它使用 AES256 CFB 模式使用 libgcrypt 加密一些数据,然后将加密的数据传递回 java 应用程序以进行进一步处理。
但是,当我尝试通过再次将数据传递到共享库来解密数据时,我无法再取回原始纯文本。看来,如果我加密和解密相同的数据而不将其传回 Java 应用程序,我将得到原始的纯文本。
我认为这是我用来将加密数据存储到 NewStringUTF() (即 env->NewStringUTF(buf))的 char 缓冲区的转换,以发送回导致问题的 java,所以有吗获取/将加密数据的输出转换为ascii 或者是否还有其他解决办法?
非常感谢, 富
Hey, I m developing a JNI shared library which uses AES256 CFB mode to encrypt some data using libgcrypt and then passing the encrypted the data back into java app for further processing.
However, when I try to decrypt the data by passing it again to the shared library I can no longer get the original plain text back. It seems that if I encrypted and decrypted the same data without passing it back to the Java app I would get the original plain text back.
I was thinking that it was the conversion of the char buffer that I used to store the encrypted data to a NewStringUTF() (ie env->NewStringUTF(buf)) to send back to the java that was causing the issue so is there away to get/convert the output of the encrypted data to ascii or if there was some other work around?
Many thanks,
Foo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么只使用 JNI 和外部库来加密字符串?使用Java内置的
javax.crypto.Cipher
类。但是,关于您的实际问题,您应该将数据作为字节数组而不是字符串传递。密码对字节进行操作,而不是抽象的 Unicode 代码点。
Why are you using JNI and external libraries just to encrypt a string? Use Java's built-in
javax.crypto.Cipher
class.However, regarding your actual question, you should be passing the data as a byte array, not a string. Ciphers operate on bytes, not abstract Unicode codepoints.