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).
public func generatePrivateKey(
withSeed randomSeed: String?
) throws -> String
Name | Type | Description |
---|---|---|
randomSeed | String? | An optional seed string to generate the private key. If `nil`, a random seed is used. |
Type | Description |
---|---|
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
Type | Description |
---|---|
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.
public func derivePublicKey(
from keyPriv: String
) throws -> String
Name | Type | Description |
---|---|---|
keyPriv | String | The private key in WIF format (Wallet Import Format) from which the public key will be derived. |
Type | Description |
---|---|
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.
public func derivePrivateKey(
from password: String,
and salt: String
) throws -> String
Name | Type | Description |
---|---|---|
password | String | The base string (password) used for private key generation. |
salt | String | A string used as salt for private key generation. |
Type | Description |
---|---|
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).
public func signData(
_ data: Data,
with privateKey: String
) throws -> Data
Name | Type | Description |
---|---|---|
data | Data | The data to be signed, provided as `Data`. |
privateKey | String | The private key (WIF format) used for signing the data. |
Type | Description |
---|---|
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.
public func encryptDataSymmetric(
_ data: Data,
with symmetricKey: Data
) throws -> Data
Name | Type | Description |
---|---|---|
data | Data | The data to be encrypted, provided as `Data`. |
symmetricKey | Data | The 256-bit symmetric key used for AES encryption. |
Type | Description |
---|---|
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.
public func decryptDataSymmetric(
_ data: Data, /// test
with symmetricKey: Data
) throws -> Data
Name | Type | Description |
---|---|---|
data | Data | The encrypted data to be decrypted, provided as `Data`. |
symmetricKey | Data | The 256-bit symmetric key used for AES decryption. |
Type | Description |
---|---|
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).
public func convertPEMKeyToWIFKey(
_ pemKey: String
) throws -> String
Name | Type | Description |
---|---|---|
pemKey | String | The private key in PEM format. |
Type | Description |
---|---|
String | The converted private key in WIF format as a `String`. |
verifySignature(data:signature:publicKey:)
Validate a signature of data using given key.
public func verifySignature(
data: Data,
signature: Data,
publicKey: String
) throws -> Bool
Name | Type | Description |
---|---|---|
data | Data | buffer containing the data signature of which is being verified. |
signature | Data | signature to be verified. |
publicKey | String | public ECC key in BASE58DER format used to validate data. |
Type | Description |
---|---|
Bool | data validation result. |