Discuss this help topic in SecureBlackbox Forum

XML: Use session key for encryption

To encrypt using a session key and using symmetric key wrap method (shared secret key encryption algorithm) you would need to do the following:

  1. Set TElXMLEncryptor.EncryptionMethod property to the desired encryption method;
  2. Set TElXMLEncryptor.EncryptKey property to true;
  3. Set TElXMLEncryptor.KeyEncryptionType property to xetKeyWrap value, which tells the component, that the session key will be wrapped;
  4. Set TElXMLEncryptor.KeyWrapMethod property to desired key wrap method;
  5. Create an instance of TElXMLKeyInfoSymmetricData class, which will be used as a session key, then generate a random key and initialization vector and assign this key object to TElXMLEncryptor.KeyData property;
  6. Create another instance of TElXMLKeyInfoSymmetricData class, set the user key, and then assign this key object to TElXMLEncryptor.KeyEncryptionKeyData property;
  7. Proceed to an encryption

C#:


Encryptor.EncryptionMethod = TElXMLEncryptionMethod.xemAES;
Encryptor.EncryptKey = true;
Encryptor.KeyEncryptionType = TElXMLKeyEncryptionType.xetKeyWrap;
Encryptor.KeyWrapMethod = TElXMLKeyWrapMethod.xwmCamellia256;

TElXMLKeyInfoSymmetricData SymKeyData = new TElXMLKeyInfoSymmetricData(true);
SymKeyData.Key.Generate(32 * 8);
SymKeyData.Key.GenerateIV(16 * 8);
Encryptor.KeyData = SymKeyData;

TElXMLKeyInfoSymmetricData SymKEKData = new TElXMLKeyInfoSymmetricData(true);
SymKEKData.Key.Key = UserKey;
Encryptor.KeyEncryptionKeyData = SymKEKData;
// encrypt
...
Delphi:

Encryptor.EncryptionMethod := xemAES;
Encryptor.EncryptKey := true;
Encryptor.KeyEncryptionType := xetKeyWrap;
Encryptor.KeyWrapMethod := xwmCamellia256;

SymKeyData := TElXMLKeyInfoSymmetricData.Create(true);
SymKeyData.Key.Generate(SizeOf(TAESKey256) * 8);
SymKeyData.Key.GenerateIV(16 * 8);
Encryptor.KeyData := SymKeyData;

SymKEKData := TElXMLKeyInfoSymmetricData.Create(true);
SymKEKData.Key.Key := UserKey;
Encryptor.KeyEncryptionKeyData := SymKEKData;
// encrypt
...
// clearing key objects after encryption
FreeAndNil(SymKeyData);
FreeAndNil(SymKEKData);

How To articles about XML encryption (XMLEnc)

Discuss this help topic in SecureBlackbox Forum