TWebRSAEncryption
TWebRSAEncryption
is a wrapper around the Web Crypto API
. It's recommended to first
familiarize yourself with the Web Crypto API
:
https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API
The Web Crypto API
provides native support to create, use and store cryptographic keys
without exposing the content of private keys
Below is a list of the most important properties, methods and events for the TWebRSAEncryption
. The supported algorithm is: RSA-OAEP
.
Properties for TWebRSAEncryption
Property | Description |
---|---|
ExtractableKey: Boolean | Determines if the key is extractable. If modified, it's not applied to the current key. |
Hash: TCryptoHash | The hash function to be used with the algorithm. If modified, it's not applied to the current key. |
ModulusLength: TRSAModulusLength | The length in bits of the RSA modulus. If modified, it's not applied to the current key. |
PrivateKey: TJSCryptoKey | The private CryptoKey object. |
PublicKey: TJSCryptoKey | The public CryptoKey object. |
Usages | Set of key usages. If modified, it's not applied to the current key. |
Methods for TWebRSAEncryption
Method | Description |
---|---|
Decrypt(AEncryptedData: TJSArrayBuffer; AResultType: TCryptoDecryptResultType) | Method to decrypt an encoded data with the class’s private key. The result type can be string or binary, based on what kind of data was encoded. |
DecryptP(AEncryptedData: TJSArrayBuffer; AResultType: TCryptoDecryptResultType): TJSPromise | Promise-based equivalent of Decrypt . Resolves with a TJSUint8Array or string value depending on the AResultType parameter. |
Encrypt(APlainText: string) | Method to encrypt a plain text, with the class’s public key. |
EncryptP(APlainText: string): TJSPromise | Promise-based equivalent of Encrypt(APlainText) . Resolves with a TJSArrayBuffer value. |
Encrypt(ABinary: TJSUint8Array) | Method to encrypt binary data, with the class’s public key. |
EncryptP(ABinary: TJSUint8Array): TJSPromise | Promise-based equivalent of Encrypt(ABinary) . Resolves with a TJSArrayBuffer value. |
ExportKey(AKeyType: TCryptoAsymKeyType; AFormat: TCryptoExportImportFormat) | Method to export the class’s keys. AKeyType represents which key to export. The supported formats are PKCS#8 (PEM encoded string) for private keys, SPKI (PEM encoded string) for public keys, and jwk (JSON string) for private/public keys. |
ExportKeyP(AKeyType: TCryptoAsymKeyType; AFormat: TCryptoExportImportFormat): TJSPromise | Promise-based equivalent of ExportKey . Resolves with a string value. |
ImportKey(AKey: string; AKeyType: TCryptoAsymKeyType; AFormat: TCryptoExportImportFormat) | Method to import a string formatted key. AKeyType determines which key to import (private/public). AFormat should be PKCS#8/jwk in case of a private key and SPKI/jwk in case of a public key. |
ImportKeyP(AKey: string; AKeyType: TCryptoAsymKeyType; AFormat: TCryptoExportImportFormat): TJSPromise | Promise-based equivalent of ImportKey(AKey) . Resolves with a True value. |
ImportKey(ABinary: TJSUint8Array; AKeyType: TCryptoAsymKeyType) | Method to import a key stored in binary format. Will automatically use PKCS#8 for a private key and SPKI for a public key. |
ImportKeyP(ABinary: TJSUint8Array; AKeyType: TCryptoAsymKeyType): TJSPromise | Promise-based equivalent of ImportKey(ABinary) . Resolves with a True value. |
GenerateKey | Generates a new key pair based on the current property settings. |
GenerateKeyP: TJSPromise | Promise-based equivalent of GenerateKey . Resolves with a True value . |
UnwrapKey(AImportFormat: TCryptoExportImportFormat; AKey: TJSArrayBuffer; AKeyAlgorithm: JSValue; AExtractable: Boolean; AKeyUsages: TCryptoKeyUsages) | Method to unwrap AKey with the class’s private key and algorithm. AKeyAlgorithm is the algorithm of AKey . AImportFormat must be the same as what was used for wrapping. |
UnwrapKeyP(AImportFormat: TCryptoExportImportFormat; AKey: TJSArrayBuffer; AKeyAlgorithm: JSValue; AExtractable: Boolean; AKeyUsages: TCryptoKeyUsages): TJSPromise | Promise-based equivalent of UnwrapKey . Resolves with a TJSCryptoKey value. |
WrapKey(AKey: TJSCryptoKey; AExportFormat: TCryptoExportImportFormat) | Method to wrap AKey with the class’s public key and algorithm. |
WrapKeyP(AKey: TJSCryptoKey; AExportFormat: TCryptoExportImportFormat): TJSPromise | Promise-based equivalent of WrapKey . Resolves with a TJSArrayBuffer value. |
Events for TWebRSAEncryption
Event | Description |
---|---|
OnDecryptedBinary | Event triggered when an encrypted data is decrypted and the format is binary. |
OnDecryptedString | Event triggered when an encrypted is decrypted and the format is string. |
OnEncrypted | Event triggered when a data is encrypted. |
OnError | Event triggered when there's a Promise rejection. |
OnKeyCreated | Event triggered when a key is created. |
OnKeyExportedJSON | Event triggered when a key is exported as a JSON string. |
OnKeyExportedPKCS8 | Event triggered when a key is exported in PKCS#8 format as a PEM encoded string. |
OnKeyExportedSPKI | Event triggered when a key is exported in SPKI format as a PEM encoded string. |
OnKeyUnwrapped | Event triggered when a key is unwrapped. |
OnKeyWrapped | Event triggered when a key is wrapped. |
OnPrivateKeyImported | Event triggered when a private key is imported. |
OnPublicKeyImported | Event triggered when a public key is imported. |