ECB / PKS5 / Blowfish encryption / decryption between AS3Crypto and Javax.Crypto fails with padding error
I have a private 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 I can use it with AS3Crypto? I guess I need to embed it using the [Embed] meta tag. It's mimeType = "application / octet-stream" but I'm not sure if this is correct. How do I insert and then reference this file as a secret key? The xmls I am encrypting cannot be decrypted on the Java side. Every attempt fails with this exception:
javax.crypto.BadPaddingException: The given final block is not filled correctly.
As a bonus, if anyone has experience using lib to work with a Java implementation and knows the ideal / complement / IV mode to use that would be great. 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;
a source to share
Don't know if you're still not sure how to insert binary data, but you are correct in using the tag [Embed]
(this is definitely one good way to do it).
I often include 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 information: http://dispatchevent.org/roger/embed-almost-anything-in-your-swf/
a source to share