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!
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!