Crypto
Cryptography utility object providing key generation, signature creation, and other crypto-related functionalities.
The Crypto
object operates based on provided algorithms and curve types, facilitating a generic approach to handling multiple cryptographic algorithms and their respective key types. It offers convenience methods to:
Generate private keys (generatePrivateKey)
Create digital signatures (sign)
conversion from Jwk <-> bytes (publicKeyToBytes)
Get relevant key generators and signers based on algorithmId.
Internally, it utilizes predefined mappings to pair algorithms and curve types with their respective KeyGenerator and Signer implementations, ensuring appropriate handlers are utilized for different cryptographic approaches. It also includes mappings to manage multicodec functionality, providing a mapping between byte arrays and respective key generators.
Example Usage:
val privateKey: Jwk = Crypto.generatePrivateKey(JWSAlgorithm.EdDSA, Curve.Ed25519)
Key Points:
Manages key generation and signing operations via predefined mappings to handle different crypto approaches.
Provides mechanisms to perform actions (e.g., signing, key generation) dynamically based on algorithmId AlgorithmId.
See also
for key generation functionalities.
for signing functionalities.
Functions
Computes a public key from the given private key, utilizing relevant KeyGenerator.
Generates a private key using the specified algorithmId, utilizing the appropriate KeyGenerator.
Retrieves the multicodec identifier associated with a given algorithmId.
Extracts the cryptographic curve information from a Jwk object.
Retrieves a KeyGenerator based on the provided multicodec identifier.
Retrieves a KeyGenerator based on the provided algorithmId. Currently, we provide key generators for keys that use ECC (see AlgorithmId enum)
Retrieves a Signer based on the provided algorithmId.
Retrieves a Signer to be used for verification based on the provided algorithm and curve.
Converts a Jwk public key into its byte array representation.