Discuss this help topic in SecureBlackbox Forum
XML: Use passwords or symmetric keys for decryption
To decrypt the data or the encryption key using a password or a secret (symmetric) key, you need to employ TElXMLKeyInfoSymmetricData class. All you need to do is
If you are using the instance of TElXMLKeyInfoSymmetricData class
for decryption of the data, assign it to KeyData property
of TElXMLDecryptor class.
If you are using the instance of TElXMLKeyInfoSymmetricData class
for decryption of the encryption key
(when TElXMLDecryptor.KeyEncryptionType property is set to xetKeyWrap),
assign it to TElXMLDecryptor.KeyEncryptionKeyData property.
Note, that you can use TElXMLDecryptor.KeyName property as a hint for how to select the key.
C#:
TElXMLKeyInfoSymmetricData SymKeyData = new TElXMLKeyInfoSymmetricData(true);
SymKeyData.Key.Key = UserKey;
if (!Decryptor.EncryptKey)
Decryptor.KeyData = SymKeyData;
else
{
if (Decryptor.KeyEncryptionType == SBXMLSec.Unit.xetKeyWrap)
Decryptor.KeyEncryptionKeyData = SymKeyData;
else
{
// set asymmetric private key
}
}
// decrypt
...
// clearing key objects after decryption
SymKeyData.Dispose();
Delphi:
SymKeyData := TElXMLKeyInfoSymmetricData.Create(True);
SymKeyData.Key.Key := UserKey;
if not Decryptor.EncryptKey then
Decryptor.KeyData := SymKeyData
else
begin
if Decryptor.KeyEncryptionType = xetKeyWrap then
Decryptor.KeyEncryptionKeyData := SymKeyData
else
// set asymmetric private key
end;
// decrypt
...
// clearing key objects after decryption
FreeAndNil(SymKeyData);