0

Trying to read string from Org.BouncyCastle.Asn1.Crmf.AttributeTypeAndValue.
The string value read from the AttributeTypeAndValue contains the junk value in the beginning.

My code:

//create type value
string id = "1.2";
string value = "hello";
var derValue = new DerPrintableString(value);
var typeValue = new Org.BouncyCastle.Asn1.Crmf.AttributeTypeAndValue(id, derValue);

//read type value
var decodedValue = new DerPrintableString(typeValue.Value.GetDerEncoded());
Console.WriteLine("Original: {0}, Decoded: {1}", 
            derValue.GetString(), decodedValue.GetString());

The output for above code is,
enter image description here

Please help me extract the original string value from AttributeTypeAndValue without junk characters.

4

1 回答 1

0

找到了解决方案。问题在于,

var decodedValue = new DerPrintableString(typeValue.Value.GetDerEncoded());

将其更改为以下内容有助于我提取没有垃圾值的字符串,

var decodedValue = DerPrintableString.GetInstance(typeValue.Value);
于 2012-08-09T21:41:00.600 回答