Encrypt/Decrypt ECB/PKS5/Blowfish between AS3Crypto & Javax.Crypto fails with padding error
- by BlueDude
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;