Adobe Flex/Air Encryption/Decryption Compatible with .Net

Flex and Air Encryption compatible with .Net

I have been working to decrypt whether it is AES Rijndael or Tripple DES .net encrypted data with flex action script as3crpto encryption library by hurlant that could be found and downloaded from here

.Net C# Code

public  string Encrypt()
    {
        byte[] keyArray;
        // path of file to encrypt
        byte[] toEncryptArray = File.ReadAllBytes(txt_FilePath.Text);
        string key = "e6408bb8610466fe67d46357f9445f2b";

        keyArray = UTF8Encoding.UTF8.GetBytes(key);

        System.Security.Cryptography.RijndaelManaged aes = new  RijndaelManaged();
        //set the secret key algorithm
        aes.Key = keyArray;
        //mode of operation. there are other 4 modes. We choose ECB(Electronic code Book)
        aes.Mode = CipherMode.ECB;
        ICryptoTransform cTransform = aes.CreateEncryptor();
        //transform the specified region of bytes array to resultArray
        byte[] resultArray = cTransform.TransformFinalBlock
                (toEncryptArray, 0, toEncryptArray.Length);
        //Release resources held
        aes.Clear();
        //Return the encrypted data into unreadable string format
        return UTF8Encoding.UTF8.GetString(resultArray);
}

//*******Decryption*********

        public  string Decrypt()
        {
            byte[] keyArray;
            //get the byte code of the string
            byte[] toEncryptArray = File.ReadAllBytes(txt_FilePath.Text);
            string key = "e6408bb8610466fe67d46357f9445f2b";
            keyArray = UTF8Encoding.UTF8.GetBytes(key);

            System.Security.Cryptography.RijndaelManaged aes = new RijndaelManaged();
            //set the secret key for algorithm
            aes.Key = keyArray;
            //mode of operation. there are other 4 modes.
            //We choose ECB(Electronic code Book)
            aes.Mode = CipherMode.ECB;

            ICryptoTransform cTransform = aes.CreateDecryptor();
            byte[] resultArray = cTransform.TransformFinalBlock
                    (toEncryptArray, 0, toEncryptArray.Length);
            //Release resources held by Encryptor
            aes.Clear();

            return UTF8Encoding.UTF8.GetString(resultArray);

        }

Flex/Air Code

public function encrypt(filePath:String,encryptKey:String):ByteArray
		{
			var fileToEncrypt:ByteArray;
			try{
				var file:File = File.desktopDirectory.resolvePath(filePath);
				 fileToEncrypt= new ByteArray();

				var stream:FileStream = new FileStream();
				stream.open( file, FileMode.READ);
				stream.readBytes(fileToEncrypt);
				stream.close();

				var key:ByteArray = Hex.toArray(Hex.fromString(encryptKey));
				var aes:ICipher = Crypto.getCipher("aes-ecb", key, new PKCS5);
				aes.encrypt(fileToEncrypt);

			}catch (error:Error){return "";}
			return fileToEncrypt;
		}

//*******Decryption*********

public function decrypt(filePath:String,encryptKey:String):ByteArray
		{
			var fileToDecrypt:ByteArray;
			try{
				var file:File = File.desktopDirectory.resolvePath(filePath);
				 fileToDecrypt = new ByteArray();

				var stream:FileStream = new FileStream();
				stream.open( file, FileMode.READ);
				stream.readBytes(fileToDecrypt);
				stream.close();

				var key:ByteArray = Hex.toArray(Hex.fromString(encryptKey));
				var aes:ICipher = Crypto.getCipher("aes-ecb", key, new PKCS5);
				aes.decrypt(fileToDecrypt);

			}catch (error:Error){return "";}
			return fileToDecrypt;
		}

You may also like...

1 Response

  1. Originative says:

    its cool man … can i post it on my blog too?

Leave a Reply

Your email address will not be published. Required fields are marked *