Search code examples
actionscript-3encryptionas3crypto

Using as3Crypto to encrypt/decrypt with only URL Query save chars


I was using as3Crypto with no probs http://www.zedia.net/2009/as3crypto-and-php-what-a-fun-ride/

but it produces a string which includes equal (and probably other URL Query unsafe characters). Is there a way to encrypt like this?

Current code below:

public function encrypt(txt:String = ''):String
{
    var data:ByteArray = Hex.toArray(Hex.fromString(txt));      
    var pad:IPad = new PKCS5;
    var mode:ICipher = Crypto.getCipher(type, key, pad);
    pad.setBlockSize(mode.getBlockSize());
    mode.encrypt(data);
    return ''+Base64.encodeByteArray(data);
}

Solution

  • Yes, base 64 encoding is the normal way to do this, although you must still URL escape the result, because Base64 contains unsafe characters as well ('/', '+' and '=' to be precise).