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

  1. create an instance of TElXMLKeyInfoSymmetricData class;
  2. create an instance of TElSymmetricKeyMaterial class and assign it to KeyData property of TElXMLKeyInfoSymmetricData class;
  3. set TElSymmetricKeyMaterial.Algorithm property of to the desired symmetric algorithm;
  4. set the TElSymmetricKeyMaterial.Key and TElSymmetricKeyMaterial.IV (if needed) properties

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);

How To articles about XML encryption (XMLEnc)

Discuss this help topic in SecureBlackbox Forum