PrivMX DOCS
API Reference/PrivMX Endpoint Swift Extra/Crypto

CryptoApi

Swift wrapper for privmx.NativeCryptoApiWrapper. This class provides cryptographic functions such as key generation, encryption, and decryption, as well as signing data. It wraps the underlying C++ implementation for use in Swift.

Methods

generatePrivateKey(withSeed:)

Generates a new Private Key, which can be used for accessing PrivMX Bridge. This method generates a private key using an optional base string (seed) for added randomness. The generated key is returned in WIF (Wallet Import Format).

Params

randomSeed

String?

An optional seed string to generate the private key. If nil, a random seed is used.

public func generatePrivateKey(
withSeed randomSeed: String?
) throws -> String

Returns

String · A WIF formatted private key as a String.

generateKeySymmetric()

Generates a new Symmetric Key for AES encryption. This method creates a 256-bit symmetric key, which can be used for AES encryption and decryption.

public func generateKeySymmetric(
) throws -> Data

Returns

Data · A 256-bit symmetric key as Data.

derivePublicKey(from:)

Derives a Public Key from a given Private Key. This method derives the corresponding public key from a provided private key, formatted in WIF.

Params

keyPriv

String

The private key in WIF format (Wallet Import Format) from which the public key will be derived.

public func derivePublicKey(
from keyPriv: String
) throws -> String

Returns

String · The derived public key as a String.

derivePrivateKey(from:and:)

Deterministically derives a Private Key from a password and salt. This method generates a private key using a combination of a password and salt. The resulting private key is derived in a deterministic way, ensuring the same password and salt will always produce the same private key.

Params

password

String

The base string (password) used for private key generation.

salt

String

A string used as salt for private key generation.

public func derivePrivateKey(
from password: String,
and salt: String
) throws -> String

Returns

String · The derived private key in WIF format (Wallet Import Format) as a String.

derivePrivateKey2(from:and:)

Deterministically derives a Private Key from a password and salt. This method generates a private key using a combination of a password and salt. The resulting private key is derived in a deterministic way, ensuring the same password and salt will always produce the same private key.

Params

password

String

The base string (password) used for private key generation.

salt

String

A string used as salt for private key generation.

public func derivePrivateKey2(
from password: String,
and salt: String
) throws -> String

Returns

String · The derived private key in WIF format (Wallet Import Format) as a String.

signData(_:with:)

Signs the given data using a Private Key. This method creates a digital signature for the provided data using a specified private key (in WIF format).

Params

data

Data

The data to be signed, provided as Data.

privateKey

String

The private key (WIF format) used for signing the data.

public func signData(
_ data: Data,
with privateKey: String
) throws -> Data

Returns

Data · The signed data as Data.

encryptDataSymmetric(_:with:)

Encrypts data using AES symmetric encryption. This method encrypts the provided data using AES encryption with a 256-bit symmetric key.

Params

data

Data

The data to be encrypted, provided as Data.

symmetricKey

Data

The 256-bit symmetric key used for AES encryption.

public func encryptDataSymmetric(
_ data: Data,
with symmetricKey: Data
) throws -> Data

Returns

Data · The encrypted data as Data.

decryptDataSymmetric(_:with:)

Decrypts data using AES symmetric encryption. This method decrypts the provided data using AES encryption with a 256-bit symmetric key.

Params

data

Data

The encrypted data to be decrypted, provided as Data.

symmetricKey

Data

The 256-bit symmetric key used for AES decryption.

public func decryptDataSymmetric(
_ data: Data, /// test
with symmetricKey: Data
) throws -> Data

Returns

Data · The decrypted data as Data.

convertPEMKeyToWIFKey(_:)

Converts a PEM formatted key to WIF format. This method converts a private key from PEM (Privacy-Enhanced Mail) format to Wallet Import Format (WIF).

Params

pemKey

String

public func convertPEMKeyToWIFKey(
_ pemKey: String
) throws -> String

Returns

String · The converted private key in WIF format as a String.

verifySignature(data:signature:publicKey:)

Params

data

Data

signature

Data

publicKey

String

public func verifySignature(
data: Data,
signature: Data,
publicKey: String
) throws -> Bool

Returns

Bool ·

verifySignature(_:of:with:)

Validate a signature of data using given key.

Params

signature

Data

signature to be verified.

data

Data

buffer containing the data signature of which is being verified.

publicKey

String

public ECC key in BASE58DER format used to validate data.

public func verifySignature(
_ signature: Data,
of data: Data,
with publicKey: String
) throws -> Bool

Returns

Bool · data validation result.

convertPGPAsn1KeyToBase58DERKey(_:)

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

Params

pgpKey

String

public key to convert

public func convertPGPAsn1KeyToBase58DERKey(
_ pgpKey: String
) throws -> String

Returns

String · public key in base58DER format

generateBip39(ofStrength:usingPassword:)

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

password

String

the password used to generate the Key

public func generateBip39(
ofStrength strength: size_t,
usingPassword password: String = ""
) throws -> BIP39

Returns

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

fromMnemonic(_:usingPassword:)

Generates ECC key using BIP-39 mnemonic.

Params

mnemonic

String

password

String

public func fromMnemonic(
_ mnemonic: String,
usingPassword password: String = ""
) throws -> BIP39

Returns

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

fromEntropy(_:usingPassword:)

Generates ECC key using BIP-39 entropy.

Params

entropy

Data

password

String

public func fromEntropy(
_ entropy: Data,
usingPassword password: String = ""
) throws -> BIP39

Returns

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

entropyToMnemonic(_:)

Converts BIP-39 mnemonic to entropy.

Params

entropy

Data

BIP-39 entropy

public func entropyToMnemonic(
_ entropy: Data
) throws -> String

Returns

String · BIP-39 mnemonic

mnemonicToEntropy(_:)

Converts BIP-39 mnemonic to entropy.

Params

mnemonic

String

BIP-39 mnemonic

public func mnemonicToEntropy(
_ mnemonic: String
) throws -> Data

Returns

Data · BIP-39 entropy

mnemonicToSeed(_:usingPassword:)

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

Params

mnemonic

String

password

String

public func mnemonicToSeed(
_ mnemonic: String,
usingPassword password: String = ""
) throws -> Data

Returns

Data · 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.

PrivMX Endpoint Swift v2.3

This package is not up to date with the core documentation. Some of the features you've seen described in other parts of the documentation might not be mentioned here. Those changes do not influence compatibility, however