在 AS3Crypto 和 AS3Crypto 之间加密/解密 ECB/PKS5/Blowfish Javax.Crypto 因填充错误而失败
我有一个密钥作为文件发送给我,这样我就可以使用 Blowfish 加密一些 xml 数据。 如何访问密钥以便将其与 AS3Crypto 一起使用? 我假设我需要使用 [Embed] 元标记来嵌入它。 它是 mimeType="application/octet-stream" 但我不确定这是否正确。 如何嵌入该文件,然后引用该文件作为密钥? 我正在加密的 xml 无法在 Java 端解密。 每次尝试都会失败,并出现以下异常:
javax.crypto.BadPaddingException:给定的最终块未正确填充。
作为奖励,如果有人有使用该库来处理 Java 实现的经验,并且知道要使用的理想模式/填充/IV,那就太棒了。 谢谢!
//keyFile is an embedded asset. I was given a file to use as the key
var kdata:ByteArray = new keyFile() as ByteArray;
//Convert orderXML to Base64
var orderData:ByteArray = Base64.decodeToByteArray(String(orderXML));
//Cipher name
var cname:String = "simple-blowfish-ecb";
var pad:IPad = new PKCS5;
var mode:ICipher = Crypto.getCipher(cname, kdata, pad);
//not sure if this is necessary. seems to be also set in mode
pad.setBlockSize(mode.getBlockSize());
mode.encrypt(orderData);
var transmitXML:String = Base64.encodeByteArray(orderData);
//DEBUG: Output to TextArea
storePanel.statusBox.text += "\n--TRANSMIT--\n"+transmitXML;
I have a secret key that was sent to me as a file so I can encrypt some xml data using Blowfish. How do I access the key so that I can use it with AS3Crypto? I assume I need to Embed it using the [Embed] meta tag. It's mimeType="application/octet-stream" but I'm not sure if thats right. How do I embed, then reference this file as the secret key? The xmls that I'm encrypting cannot be decrypted on the Java side. Each attempt fails with this exception:
javax.crypto.BadPaddingException: Given final block not properly padded.
As a bonus, if anyone has experience using the lib to work with the Java implementation and knows the ideal mode/padding/IV to use that would be awesome. Thanks!
//keyFile is an embedded asset. I was given a file to use as the key
var kdata:ByteArray = new keyFile() as ByteArray;
//Convert orderXML to Base64
var orderData:ByteArray = Base64.decodeToByteArray(String(orderXML));
//Cipher name
var cname:String = "simple-blowfish-ecb";
var pad:IPad = new PKCS5;
var mode:ICipher = Crypto.getCipher(cname, kdata, pad);
//not sure if this is necessary. seems to be also set in mode
pad.setBlockSize(mode.getBlockSize());
mode.encrypt(orderData);
var transmitXML:String = Base64.encodeByteArray(orderData);
//DEBUG: Output to TextArea
storePanel.statusBox.text += "\n--TRANSMIT--\n"+transmitXML;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不知道您是否仍然不确定如何嵌入二进制数据,但使用
[Embed]
标记是正确的(这当然是一种好方法)。我经常这样嵌入:
更多信息:
http://dispatchevent.org/roger/embed-almost-anything -在你的swf中/
Dunno if you're still unsure about how to embed binary data, but you're right about using the
[Embed]
tag (it's certainly one good way of doing it).I often embed like this:
More info:
http://dispatchevent.org/roger/embed-almost-anything-in-your-swf/