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:
C#:
Encryptor.EncryptionMethod = SBXMLSec.Unit.xemAES;
Encryptor.EncryptKey = true;
Encryptor.KeyEncryptionType = SBXMLSec.Unit.xetKeyWrap;
Encryptor.KeyWrapMethod = SBXMLSec.Unit.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
...
// clearing key objects after encryption
SymKeyData.Dispose();
SymKEKData.Dispose();
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);