views:

278

answers:

1

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;
}
+2  A: 

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.

Beaner
This is exactly the problem. VB6 defaults to ANSI (code page 1252).var ansi = Encoding.GetEncoding(1252);
William Edmondson