Question

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;
Was it helpful?

Solution

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/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top