Discuss this help topic in SecureBlackbox Forum
Use RSA keys, X.509 certificates or OpenPGP keys for decryption
X.509 certificates, OpenPGP keys and RSA keys can not be used to encrypt or decrypt the data. When there's a need to use public key cryptography for encryption, a symmetric session key is generated and used to encrypt the actual data. Then the public key is used to encrypt the session key itself.
If the session key was encrypted and included with the encrypted data, TElXMLDecryptor.EncryptKey property is true and TElXMLDecryptor.KeyEncryptionType property is set to xetKeyTransport. In this case you need to use asymmetric private key to decrypt the data.
Note, that you can use TElXMLDecryptor.KeyName property as a hint for how to select the key.
For RSA keys:
For X.509 certificates:
For OpenPGP keys:
C#:
if (Decryptor.EncryptKey && (Decryptor.KeyEncryptionType == SBXMLSec.Unit.xetKeyTransport))
{
// set asymmetric private key
TElXMLKeyInfoX509Data X509KeyData = new TElXMLKeyInfoX509Data(true);
X509KeyData.Certificate = UserCertificate;
Decryptor.KeyEncryptionKeyData = X509KeyData;
// decrypt
...
// clearing key objects after decryption
SymKeyData.Dispose();
}
Delphi:
if Decryptor.EncryptKey and (Decryptor.KeyEncryptionType = xetKeyTransport) then
begin
X509KeyData := TElXMLKeyInfoX509Data.Create(true);
X509KeyData.Certificate := UserCertificate;
Decryptor.KeyEncryptionKeyData := X509KeyData;
// decrypt
...
// clearing key objects after encryption
FreeAndNil(X509KeyData);
end;