Persits Software, Inc. Knowledge Base Articles

Bad Data error during decryption

Problem Description

When decrypting with AspEncrypt, the methods Key.DecryptText or Key.DecryptFile may return the following error:

Persits.CryptoManager.1 error '800a0010'
Bad Data.

or

Persits.CryptoManager.1 (0x800A0010)
Bad Data

Solution

There are two common reasons for this problem:

Reason 1. Encryption and decryption keys do not match

For decryption to be successful, the key used for decryption must match that used for encryption.

If a password-derived key is being used, make sure that the passwords used to generate the encryption and decryption keys match, and also that the current cryptographic service providers involved are the same.

If key size is not explicitly specified in the GenerateKeyFromPassword method, the default key size is 40 bits with the Microsoft Base CSP, and 128 bits with the Microsoft Enhanced or Strong CSP. As a result, the keys may mismatch.

Use the debug statement

Response.Write Key.Length

to make sure the key lengths match during encryption and decryption. Cryptographic Service Providers are covered in the chapter Symmetric Encryption of the AspEncrypt.com web site.

Reason 2. Data to be decrypted is invalid or corrupt
Make sure the data you feed to a DecryptXXX method was obtained via the corresponding EncryptXXX method. Also make sure the encoding methods match (Binary, Base64 or Hex).