0

I have a large amount of data encrypted with the CAPICOM library through our legacy VB6 applications.

I need to access this data from a .Net 3.5 app but am getting the error: "ASN1 bad tag value met" when I call the Decrypt method. Google has been little help in tracking down decent code samples or explanations as to what this error means.

The following code is almost exactly a replication of what was happening in the VB6 code:

static string DecryptEncryptedText(string encryptedText, string secretKey)
{
    var encryptedDataObj = new CAPICOM.EncryptedData();
    encryptedDataObj.SetSecret(secretKey, CAPICOM_SECRET_TYPE.CAPICOM_SECRET_PASSWORD);
    encryptedDataObj.Decrypt(encryptedText);
    return encryptedDataObj.Content;
}
William Edmondson
  • 3,619
  • 3
  • 32
  • 41

1 Answers1

3

When I get this error it has been because I used the wrong key to decrypt. Have you checked the encoding of your secretKey? I suspect the data was encrypted with an ANSI string in VB6 and you are using a Unicode string in your new code.

jac
  • 9,666
  • 2
  • 34
  • 63