title: Error: PKCS#5:unpad: Invalid padding value. expected [154], found [253] using as3crypto
body: <p>I downloaded as3crypto and have been trying to integrate it into my project.
  I'm trying to do a simple test to match the decrypt results I'm getting in the demo - <a href="http://crypto.hurlant.com/demo/" rel="nofollow">http://crypto.hurlant.com/demo/</a> but I'm getting the above error.</p>
  
  <p>I'm working on the Secret Key tab. I'm using AES, CBC, PKCS5 and prepending the IV.
  Both the Key and Cipher text is set to HEX.</p>
  
  <p>I first did an Encrypt and then copy the key and the cipher text to my function to test the decrypt to see if it match. I copied the code direct from the SecretTab.mxml and modified it a little to take the hard coded values.</p>
  
  <p>I wrote a small program in C# to decrypt it using the same values and it works fine.</p>
  
  <p>I verified the key and cipher text many times and it is correct.</p>
  
  <pre><code>    public static function decrypt2():void 
      {
          // 2: get a key
          var k:String = Hex.fromString("e5693983c5c21e0f6191eb025d12803d6d17c5359994bf435b964cd0c107fc2c");
          var kdata:ByteArray = Hex.toArray(k);
          //trace(String.fromCharCode(kdata[0]));
  
          // 3: get an output
          var txt:String = Hex.fromString("691682969f1946a1465ccfe19d429ace4188ee254425caa7fa84db5b1fba44a77f1dedfba7a1ffe516cb0646638e28f8ae6422b3cd63d380b21f8b8dcfbe067a");
          var data:ByteArray = Hex.toArray(txt);
  
          // 1: get an algorithm..
          var name:String = "simple-aes-cbc";              
  
          var pad:IPad = new PKCS5; //:new NullPad;
          //var pad:IPad = new NullPad();
          var mode:ICipher = Crypto.getCipher(name, kdata, pad);
          pad.setBlockSize(mode.getBlockSize());
          // if an IV is there, set it.
           if (mode is IVMode) {
                  trace("mode is IVMode");
                  var ivmode:IVMode = mode as IVMode;
                  //ivmode.IV = Hex.toArray(iv.text);
              }
          mode.decrypt(data);
          trace(Hex.fromArray(data));
      }
  </code></pre>