我有被送往我作为一个文件,这样我可以加密使用的Blowfish一些XML数据的密钥。如何访问键,以便我可以AS3Crypto使用它呢?我想我需要使用[嵌入]元标签中嵌入它。这是mime类型=“应用程序/八位字节流”,但我不知道如果这就是正确的。如何嵌入,然后引用此文件作为密钥?我正在加密个XML不能在Java端进行解密。每个尝试失败与此异常:

javax.crypto.BadPaddingException:给定最终块未正确填充。

作为奖励,如果任何人有使用的lib用Java实现的工作经验,知道理想模式/填充/四使用,将是真棒。谢谢!

//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;
有帮助吗?

解决方案

说不上来,如果你仍然不确定如何嵌入二进制数据,但你说得对有关使用[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 -in-您-SWF /

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top