PrivmxCrypto
Wrapper class for the build in Crypto.
Constructors
constructor
constructor()
Static Methods
convertPEMKeyToWIFKey
Converts a PEM key to WIF format.
static async convertPEMKeyToWIFKey(keyPEM: string)
Name | Type | Description |
---|---|---|
keyPEM | string | PEM key to convert |
Type | Description |
---|---|
Promise<string> | WIF formatted key |
decryptDataSymmetric
Decrypts given data using the provided key.
static async decryptDataSymmetric(data: Uint8Array, key: Uint8Array)
Name | Type | Description |
---|---|---|
data | Uint8Array | data to decrypt |
key | Uint8Array | key to use for decryption |
Type | Description |
---|---|
Promise<Uint8Array> | decrypted data |
deriveKeySymmetric
Derives a symmetric key from a password and salt using a key derivation function.
static async deriveKeySymmetric(password: string, salt: string)
Name | Type | Description |
---|---|---|
password | string | input password used to derive the key |
salt | string | a unique string used to ensure that the same password generates different keys |
Type | Description |
---|---|
Promise<Uint8Array> | generated derived key |
derivePrivateKey
Generates a new private key using PBKDF2.
static async derivePrivateKey(salt: string, password: string)
Name | Type | Description |
---|---|---|
salt | string | salt to use for key generation |
password | string | password to use for key generation |
Type | Description |
---|---|
Promise<string> | generated private key |
derivePublicKey
Generates a new public key from given private key.
static async derivePublicKey(privKey: string)
Name | Type | Description |
---|---|---|
privKey | string | private key to use for generating the public key |
Type | Description |
---|---|
Promise<string> | generated public key |
encryptDataSymmetric
Encrypts given data using the provided key.
static async encryptDataSymmetric(data: Uint8Array, key: Uint8Array)
Name | Type | Description |
---|---|---|
data | Uint8Array | data to encrypt |
key | Uint8Array | key to use for encryption |
Type | Description |
---|---|
Promise<Uint8Array> | encrypted data |
generateKeySymmetric
Generates a new symmetric key signData a `Uint8Array`. This function uses a cryptographic algorithm to create a secure random key.
static async generateKeySymmetric()
Type | Description |
---|---|
Promise<Uint8Array> | generated symmetric key |
generatePrivateKey
Generates a new private key.
static async generatePrivateKey(baseString: string)
Name | Type | Description |
---|---|---|
baseString | string | optional base string to use for key generation |
Type | Description |
---|---|
Promise<string> | generated private key |
signData
Signs given data using the provided private key.
static async signData(data: Uint8Array, privKey: string)
Name | Type | Description |
---|---|---|
data | Uint8Array | data to sign |
privKey | string | private key to use for signing |
Type | Description |
---|---|
Promise<Uint8Array> | signature |
verifySignature
Validate a signature of data using given key.
static async verifySignature(data: Uint8Array, signature: Uint8Array, publicKey: string)
Name | Type | Description |
---|---|---|
data | Uint8Array | buffer |
signature | Uint8Array | tof data |
publicKey | string | public ECC key in BASE58DER format used to validate data |
Type | Description |
---|---|
Promise<boolean> | validated data |