decrypting key in EncryptedKey using X509SubjectKeyIdentifier

S

srikant

Hi,

I am trying to figure out how to retrieve the decrypted key from an
<EncryptedKey> element. The <KeyInfo> has a X509SubjectKeyIdentifier
reference and I know that a corresponding certificate exists in the
LocalMachineStore.
Here is a stripped sample code -- I just want to create an EncryptedKey
element and then retrieve the key back.

public static void encKey(X509Certificate cert)
{
X509SecurityToken token = new X509SecurityToken(cert);
AES256 aes = new AES256();
ubyte[] keyData = aes.get_KeyBytes();

EncryptedKey key = new EncryptedKey(token, keyData);
key.Encrypt();

XmlElement e = key.GetXml(new XmlDocument());
XmlTextWriter tw = new XmlTextWriter(Console.get_Out());
tw.set_Formatting(Formatting.Indented);
e.WriteTo(tw);

try
{
EncryptedKey encKey = new EncryptedKey (e);
encKey.Decrypt ();
ubyte[] keybytes = encKey.get_KeyBytes ();
}
catch (Exception ex)
{
System.Console.WriteLine (ex);
}
}

Everytime I try to construct an EncryptedKey from the xml element, I
get the security fault "Referenced security token could not be
retrieved".

Do I need to set soemthing in the app.config to get this to work ?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top