TPrivateKey Delphi Reference

TPrivateKey

* This is a freeware class/component/library.

Represents an RSA private key. Provides methods for importing and exporting to/from PEM, DER, PKCS8, PVK, and XML formats. Private keys can be imported/exported to both memory and files.

Object Creation

var
obj: IPrivateKey;
...
begin
obj := TprivateKey.Create(Self).ControlInterface;

Properties

property LastErrorHtml: WideString readonly

Error information in HTML format for the last method called.

property LastErrorText: WideString readonly

Error information in plain-text format for the last method called.

property LastErrorXml: WideString readonly

Error information in XML format for the last method called.

Methods

function GetPkcs8(): OleVariant;

Gets the private key in PKCS8 format.

Returns 1 for success, 0 for failure.

function GetPkcs8Encrypted(password: WideString): OleVariant;

Writes the private key to password-protected PKCS8 format.

Returns 1 for success, 0 for failure.

function GetPkcs8EncryptedPem(password: WideString): WideString;

Writes the private key to password-protected PKCS8 PEM format.

Returns a null on failure

function GetPkcs8Pem(): WideString;

Gets the private key in PKCS8 PEM format.

Returns a null on failure

function GetRsaDer(): OleVariant;

Gets the private key in RSA DER format.

Returns 1 for success, 0 for failure.

function GetRsaPem(): WideString;

Gets the private key in RSA PEM format.

Returns a null on failure

function GetXml(): WideString;

Returns the private key in XML format. The private key is returned unencrypted and the parts are base64 encoded. The XML has this structure:

<RSAKeyValue>
  <Modulus>...</Modulus>
  <Exponent>...</Exponent>
  <P>...</P>
  <Q>...</Q>
  <DP>...</DP>
  <DQ>...</DQ>
  <InverseQ>...</InverseQ>
  <D>...</D>
</RSAKeyValue>

Returns a null on failure

function LoadEncryptedPem(pemStr: WideString, password: WideString): Integer;

Loads the private key from an in-memory encrypted PEM string.

Returns 1 for success, 0 for failure.

function LoadEncryptedPemFile(filename: WideString, password: WideString): Integer;

Loads a private key from an encrypted PEM file.

Returns 1 for success, 0 for failure.

function LoadPem(str: WideString): Integer;

Loads the private key from an in-memory PEM string.

Returns 1 for success, 0 for failure.

function LoadPemFile(filename: WideString): Integer;

Loads a private key from a PEM file.

Returns 1 for success, 0 for failure.

function LoadPkcs8(pkcs8Data: OleVariant): Integer;

Loads a private key from in-memory PKCS8 byte data.

Returns 1 for success, 0 for failure.

function LoadPkcs8Encrypted(data: OleVariant, password: WideString): Integer;

Loads a private key from in-memory password-protected PKCS8 byte data.

Returns 1 for success, 0 for failure.

function LoadPkcs8EncryptedFile(filename: WideString, password: WideString): Integer;

Loads a private key from a password-protected PKCS8 file.

Returns 1 for success, 0 for failure.

function LoadPkcs8File(filename: WideString): Integer;

Loads a private key from a PKCS8 file.

Returns 1 for success, 0 for failure.

function LoadPvk(pvkData: OleVariant, password: WideString): Integer;

Loads a private key from in-memory PVK byte data.

Returns 1 for success, 0 for failure.

function LoadPvkFile(filename: WideString, password: WideString): Integer;

Loads a private key from a PVK format file.

Returns 1 for success, 0 for failure.

function LoadRsaDer(derData: OleVariant): Integer;

Loads a private key from in-memory RSA DER byte data.

Returns 1 for success, 0 for failure.

function LoadRsaDerFile(filename: WideString): Integer;

Loads a private key from an RSA DER format file.

Returns 1 for success, 0 for failure.

function LoadXml(xmlDoc: WideString): Integer;

Loads a private key from an in-memory XML string.

Returns 1 for success, 0 for failure.

function LoadXmlFile(filename: WideString): Integer;

Loads a private key from an XML file.

Returns 1 for success, 0 for failure.

function SaveLastError(filename: WideString): Integer;

Saves the last error information to an XML formatted file.

function SavePkcs8EncryptedFile(password: WideString, filename: WideString): Integer;

Saves the private key to a password-protected PKCS8 format file.

Returns 1 for success, 0 for failure.

function SavePkcs8EncryptedPemFile(password: WideString, filename: WideString): Integer;

Saves the private key to a password-protected PKCS8 PEM format file.

Returns 1 for success, 0 for failure.

function SavePkcs8File(filename: WideString): Integer;

Saves the private key to a PKCS8 format file.

Returns 1 for success, 0 for failure.

function SavePkcs8PemFile(filename: WideString): Integer;

Saves the private key to a PKCS8 PEM format file.

Returns 1 for success, 0 for failure.

function SaveRsaDerFile(filename: WideString): Integer;

Saves the private key to a RSA DER format file.

Returns 1 for success, 0 for failure.

function SaveRsaPemFile(filename: WideString): Integer;

Saves the private key to a RSA PEM format file.

Returns 1 for success, 0 for failure.

function SaveXmlFile(filename: WideString): Integer;

Saves the private key to an XML file.

Returns 1 for success, 0 for failure.