PrivMX DOCS
API Reference/PrivMX Endpoint Swift/Crypto

CryptoApi

‘CryptoApi’ is a class representing Endpoint’s API for cryptographic operations. This class wraps the underlying C++ implementation for use in Swift.

Static Methods

create()

Creates instance of ‘CryptoApi’.

public static func create(
) -> CryptoApi

Returns

CryptoApi · CryptoApi object

Methods

signData(data:privateKey:)

Creates a signature of data using given key.

Params

data

privmx.endpoint.core.Buffer

buffer to sign

privateKey

std.string

key used to sign data

public func signData(
data: privmx.endpoint.core.Buffer,
privateKey: std.string
) throws -> privmx.endpoint.core.Buffer

Returns

privmx.endpoint.core.Buffer · signature of data

verifySignature(data:signature:publicKey:)

Validate a signature of data using given key.

Params

data

privmx.endpoint.core.Buffer

buffer

signature

privmx.endpoint.core.Buffer

signature of data to verify

publicKey

std.string

public ECC key in BASE58DER format used to validate data

public func verifySignature(
data: privmx.endpoint.core.Buffer,
signature: privmx.endpoint.core.Buffer,
publicKey: std.string
) throws -> Bool

Returns

Bool · data validation result

generateKeySymmetric()

Generates a new symmetric key.

public func generateKeySymmetric(
) throws -> privmx.endpoint.core.Buffer

Returns

privmx.endpoint.core.Buffer · generated key

generatePrivateKey(randomSeed:)

Generates a new private ECC key.

Params

randomSeed

std.string?

optional string used as the base to generate the new key

public func generatePrivateKey(
randomSeed: std.string?
) throws -> std.string

Returns

std.string · generated ECC key in WIF format

derivePrivateKey(password:salt:)

Generates a new private ECC key from a password using pbkdf2.

Params

password

std.string

the password used to generate the new key

salt

std.string

random string (additional input for the hashing function)

public func derivePrivateKey(
password: std.string,
salt: std.string
) throws -> std.string

Returns

std.string · generated ECC key in WIF format

derivePrivateKey2(password:salt:)

Generates a new private ECC key from a password using pbkdf2. This version of the derive function has a rounds count increased to 200k. This makes using this function a safer choice, but it makes the received key different than in the original version.

Params

password

std.string

the password used to generate the new key

salt

std.string

random string (additional input for the hashing function)

public func derivePrivateKey2(
password: std.string,
salt: std.string
) throws -> std.string

Returns

std.string · generated ECC key in WIF format

derivePublicKey(privKey:)

Generates a new public ECC key as a pair for an existing private key.

Params

privKey

std.string

private ECC key in WIF format

public func derivePublicKey(
privKey: std.string
) throws -> std.string

Returns

std.string · generated ECC key in BASE58DER format

encryptDataSymmetric(data:symmetricKey:)

Encrypts buffer with a given key using AES.

Params

data

privmx.endpoint.core.Buffer

buffer to encrypt

symmetricKey

privmx.endpoint.core.Buffer

key used to encrypt data

public func encryptDataSymmetric(
data: privmx.endpoint.core.Buffer,
symmetricKey: privmx.endpoint.core.Buffer
) throws -> privmx.endpoint.core.Buffer

Returns

privmx.endpoint.core.Buffer · encrypted data buffer

decryptDataSymmetric(data:symmetricKey:)

Decrypts buffer with a given key using AES.

Params

data

privmx.endpoint.core.Buffer

buffer to decrypt

symmetricKey

privmx.endpoint.core.Buffer

key used to decrypt data

public func decryptDataSymmetric(
data: privmx.endpoint.core.Buffer,
symmetricKey: privmx.endpoint.core.Buffer
) throws -> privmx.endpoint.core.Buffer

Returns

privmx.endpoint.core.Buffer · plain (decrypted) data buffer

convertPEMKeyToWIFKey(pemKey:)

Converts given private key in PEM format to its WIF format.

Params

pemKey

std.string

private key to convert

public func convertPEMKeyToWIFKey(
pemKey: std.string
)throws -> std.string

Returns

std.string · private key in WIF format

convertPGPAsn1KeyToBase58DERKey(pgpKey:)

Converts given public key in PGP format to its base58DER format.

Params

pgpKey

std.string

public key to convert

public func convertPGPAsn1KeyToBase58DERKey(
pgpKey: std.string
) throws -> std.string

Returns

std.string · public key in base58DER format

generateBip39(strength:password:)

Generates ECC key and BIP-39 mnemonic from a password using BIP-39.

Params

strength

size_t

size of BIP-39 entropy, must be a multiple of 32 between 128 and 256.

password

std.string

the password used to generate the Key

public func generateBip39(
strength: size_t,
password: std.string = std.string()
) throws -> BIP39

Returns

BIP39 · BIP39 object containing ECC Key and associated with it BIP-39 mnemonic and entropy

fromMnemonic(mnemonic:password:)

Generates ECC key using BIP-39 mnemonic.

Params

mnemonic

std.string

the BIP-39 entropy used to generate the Key

password

std.string

the password used to generate the Key

public func fromMnemonic(
mnemonic: std.string,
password: std.string = std.string()
) throws -> BIP39

Returns

BIP39 · BIP39 object containing ECC Key and associated with it BIP-39 mnemonic and entropy

fromEntropy(entropy:password:)

Generates ECC key using BIP-39 entropy.

Params

entropy

privmx.endpoint.core.Buffer

the BIP-39 entropy used to generate the Key

password

std.string

the password used to generate the Key

public func fromEntropy(
entropy: privmx.endpoint.core.Buffer,
password: std.string = std.string()
)throws -> BIP39

Returns

BIP39 · BIP39 object containing ECC Key and associated with it BIP-39 mnemonic and entropy

entropyToMnemonic(entropy:)

Converts BIP-39 mnemonic to entropy.

Params

entropy

privmx.endpoint.core.Buffer

BIP-39 entropy

public func entropyToMnemonic(
entropy: privmx.endpoint.core.Buffer
) throws -> std.string

Returns

std.string · BIP-39 mnemonic

mnemonicToEntropy(mnemonic:)

Converts BIP-39 mnemonic to entropy.

Params

mnemonic

std.string

BIP-39 mnemonic

public func mnemonicToEntropy(
mnemonic: std.string
) throws -> privmx.endpoint.core.Buffer

Returns

privmx.endpoint.core.Buffer · BIP-39 entropy

mnemonicToSeed(mnemonic:password:)

Generates a seed used to generate a key using BIP-39 mnemonic with PBKDF2.

Params

mnemonic

std.string

password

std.string

public func mnemonicToSeed(
mnemonic: std.string,
password: std.string = std.string()
) throws -> privmx.endpoint.core.Buffer

Returns

privmx.endpoint.core.Buffer · generated seed

We use cookies on our website. We use them to ensure the proper functioning of the site and, if you agree, for purposes we set, such as analytics or marketing.