2009-05-15 37 views
0

我有一個祕密密鑰作爲文件發送給我,因此我可以使用Blowfish加密一些xml數據。如何訪問密鑰,以便我可以將它與AS3Crypto一起使用?我假設我需要使用[Embed]元標記嵌入它。這是mimeType =「application/octet-stream」,但我不確定這是否正確。如何嵌入,然後將此文件作爲密鑰引用?我正在加密的xmls無法在Java端解密。每次嘗試都失敗,出現此異常:加密/解密AS3Crypto和Javax.Crypto之間的ECB/PKS5/Blowfish失敗,出現填充錯誤

javax.crypto.BadPaddingException:給定的最終塊未正確填充。作爲獎勵,如果任何人有使用lib來處理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; 

回答

1

說不上來,如果你仍然不確定如何嵌入二進制數據,但你說得對有關使用[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-your-swf/

+0

這正是問題。謝謝! – ChickensDontClap 2011-01-03 15:46:37

+0

沒有probs,喲... – aaaidan 2011-01-19 02:29:35

相關問題