在 AS3Crypto 和 AS3Crypto 之间加密/解密 ECB/PKS5/Blowfish Javax.Crypto 因填充错误而失败

发布于 2024-07-20 14:45:39 字数 1026 浏览 6 评论 0原文

我有一个密钥作为文件发送给我,这样我就可以使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

策马西风 2024-07-27 14:45:39

不知道您是否仍然不确定如何嵌入二进制数据,但使用 [Embed] 标记是正确的(这当然是一种好方法)。

我经常这样嵌入:

[Embed(source="myKeyFile.key", mimeType="application/octet-stream")]
private const _KeyFile:Class;
private var keyFile:ByteArray = new _KeyFile();

...

trace(keyFile.length + " bytes"); // XYZ bytes

更多信息:
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:

[Embed(source="myKeyFile.key", mimeType="application/octet-stream")]
private const _KeyFile:Class;
private var keyFile:ByteArray = new _KeyFile();

...

trace(keyFile.length + " bytes"); // XYZ bytes

More info:
http://dispatchevent.org/roger/embed-almost-anything-in-your-swf/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文