DiceKeys Seeded Cryptography Library
SignatureVerificationKey Class Reference

A SignatureVerificationKey is used to verify that messages were signed by its corresponding SigningKey. SigningKeys generate signatures, and by verifying a message/signature pair the SignatureVerificationKey can confirm that the message was indeed signed using the SigningKey. The key pair of the SigningKey and SignatureVerificationKey is generated from a seed and a set of options in JSON Format for Recipes. More...

#include <signature-verification-key.hpp>

Public Member Functions

 SignatureVerificationKey (const std::vector< unsigned char > &keyBytes, const std::string &recipe)
 Construct by passing the classes members. More...
 
const std::string toJson (int indent=-1, const char indent_char=' ') const
 Serialize this object to a JSON-formatted string. More...
 
bool verify (const unsigned char *message, const size_t messageLength, const std::vector< unsigned char > &signature) const
 Verify that a signature is valid in order to prove that a message has been signed with the SigningKey from which this SignatureVerificationKey was generated. More...
 
bool verify (const std::vector< unsigned char > &message, const std::vector< unsigned char > &signature) const
 Verify that a signature is valid in order to prove that a message has been signed with the SigningKey from which this SignatureVerificationKey was generated. More...
 
bool verify (const SodiumBuffer &message, const std::vector< unsigned char > &signature) const
 Verify that a signature is valid in order to prove that a message has been signed with the SigningKey from which this SignatureVerificationKey was generated. More...
 
const std::vector< unsigned char > getKeyBytes () const
 Get the raw signature verification key as a byte vector. More...
 
const std::string getKeyBytesAsHexDigits () const
 Get the raw signature-verification key as a string of hex digits. More...
 
const std::string getRecipeJson () const
 Get the JSON-formatted recipe string used to generate the public-private key pair. More...
 
const SodiumBuffer toSerializedBinaryForm () const
 Serialize to byte array as a list of: (signatureVerificationKeyBytes, recipe) More...
 
const std::string toOpenSshPublicKey () const
 Convert the signature-verification key to an OpenSSH public key string.
 

Static Public Member Functions

static SignatureVerificationKey fromJson (const std::string &signatureVerificationKeyAsJson)
 Construct (reconstitute) a SignatureVerificationKey from JSON format, which may ahve been generated by calling toJson on another SignatureVerificationKey. More...
 
static bool verify (const unsigned char *signatureVerificationKeyBytes, const size_t signatureVerificationKeyBytesLength, const unsigned char *message, const size_t messageLength, const unsigned char *signature, const size_t signatureLength)
 Avoid Using Verify a message's signature using a raw libsodium verification key More...
 
static bool verify (const std::vector< unsigned char > &signatureVerificationKeyBytes, const unsigned char *message, const size_t messageLength, const std::vector< unsigned char > &signature)
 Avoid Using Verify a message's signature using a raw libsodium verification key More...
 
static SignatureVerificationKey fromSerializedBinaryForm (const SodiumBuffer &serializedBinaryForm)
 Deserialize from a byte array stored as a list of: (signatureVerificationKeyBytes, recipe) More...
 

Public Attributes

const std::vector< unsigned char > signatureVerificationKeyBytes
 The raw binary representation of the cryptographic key.
 
const std::string recipe
 A JSON Format for Recipes string used to specify how this key is derived.
 

Detailed Description

A SignatureVerificationKey is used to verify that messages were signed by its corresponding SigningKey. SigningKeys generate signatures, and by verifying a message/signature pair the SignatureVerificationKey can confirm that the message was indeed signed using the SigningKey. The key pair of the SigningKey and SignatureVerificationKey is generated from a seed and a set of options in JSON Format for Recipes.

To derive a SignatureVerificationKey from a seed, first derive the corresponding SigningKey and then call SigningKey::getSignatureVerificationKey.

Constructor & Destructor Documentation

◆ SignatureVerificationKey()

SignatureVerificationKey::SignatureVerificationKey ( const std::vector< unsigned char > &  keyBytes,
const std::string &  recipe 
)

Construct by passing the classes members.

Parameters
keyBytes
recipe

Member Function Documentation

◆ fromJson()

SignatureVerificationKey SignatureVerificationKey::fromJson ( const std::string &  signatureVerificationKeyAsJson)
static

Construct (reconstitute) a SignatureVerificationKey from JSON format, which may ahve been generated by calling toJson on another SignatureVerificationKey.

Parameters
signatureVerificationKeyAsJson

◆ fromSerializedBinaryForm()

SignatureVerificationKey SignatureVerificationKey::fromSerializedBinaryForm ( const SodiumBuffer serializedBinaryForm)
static

Deserialize from a byte array stored as a list of: (signatureVerificationKeyBytes, recipe)

Stored in SodiumBuffer's fixed-length list format. Strings are stored as UTF8 byte arrays.

◆ getKeyBytes()

const std::vector< unsigned char > SignatureVerificationKey::getKeyBytes ( ) const

Get the raw signature verification key as a byte vector.

Returns
const std::vector<unsigned char>

◆ getKeyBytesAsHexDigits()

const std::string SignatureVerificationKey::getKeyBytesAsHexDigits ( ) const

Get the raw signature-verification key as a string of hex digits.

Returns
const std::string a string containing only hex digits (and no "0x").

◆ getRecipeJson()

const std::string SignatureVerificationKey::getRecipeJson ( ) const
inline

Get the JSON-formatted recipe string used to generate the public-private key pair.

Returns
const std::string in JSON Format for Recipes

◆ toJson()

const std::string SignatureVerificationKey::toJson ( int  indent = -1,
const char  indent_char = ' ' 
) const

Serialize this object to a JSON-formatted string.

It can be reconstituted by calling the constructor with this string.

Parameters
indentThe number of characters to indent the JSON (optional)
indent_charThe character with which to indent the JSON (optional)
Returns
const std::string

◆ toSerializedBinaryForm()

const SodiumBuffer SignatureVerificationKey::toSerializedBinaryForm ( ) const

Serialize to byte array as a list of: (signatureVerificationKeyBytes, recipe)

Stored in SodiumBuffer's fixed-length list format. Strings are stored as UTF8 byte arrays.

◆ verify() [1/5]

bool SignatureVerificationKey::verify ( const SodiumBuffer message,
const std::vector< unsigned char > &  signature 
) const

Verify that a signature is valid in order to prove that a message has been signed with the SigningKey from which this SignatureVerificationKey was generated.

Parameters
messageThe message to verify the signature of
signatureThe signature generated by corresponding SigningKey when by calling SigningKey::generateSignature with the same message.
Returns
true if the signature is valid indicating the message was indeed signed by the corresponding SigningKey
false if the verification fails.

◆ verify() [2/5]

bool SignatureVerificationKey::verify ( const std::vector< unsigned char > &  message,
const std::vector< unsigned char > &  signature 
) const

Verify that a signature is valid in order to prove that a message has been signed with the SigningKey from which this SignatureVerificationKey was generated.

Parameters
messageThe message to verify the signature of
signatureThe signature generated by corresponding SigningKey when by calling SigningKey::generateSignature with the same message.
Returns
true if the signature is valid indicating the message was indeed signed by the corresponding SigningKey
false if the verification fails.

◆ verify() [3/5]

bool SignatureVerificationKey::verify ( const std::vector< unsigned char > &  signatureVerificationKeyBytes,
const unsigned char *  message,
const size_t  messageLength,
const std::vector< unsigned char > &  signature 
)
static

Avoid Using Verify a message's signature using a raw libsodium verification key

Instead of using this static method, we recommend you use the seal method on an instance of a SignatureVerificationKey object.

Parameters
signatureVerificationKeyBytessignatureVerificationKeyBytes The raw key bytes
messageThe message that was signed
messageLengthThe length of the message
signatureThe signature generated by corresponding SigningKey when by calling SigningKey::generateSignature with the same message.
Returns
true if the signature is valid indicating the message was indeed signed by the corresponding SigningKey
false if the verification fails.

◆ verify() [4/5]

bool SignatureVerificationKey::verify ( const unsigned char *  message,
const size_t  messageLength,
const std::vector< unsigned char > &  signature 
) const

Verify that a signature is valid in order to prove that a message has been signed with the SigningKey from which this SignatureVerificationKey was generated.

Parameters
messageThe message to verify the signature of
messageLengthThe length of the message
signatureThe signature generated by corresponding SigningKey when by calling SigningKey::generateSignature with the same message.
Returns
true if the signature is valid indicating the message was indeed signed by the corresponding SigningKey
false if the verification fails.

◆ verify() [5/5]

bool SignatureVerificationKey::verify ( const unsigned char *  signatureVerificationKeyBytes,
const size_t  signatureVerificationKeyBytesLength,
const unsigned char *  message,
const size_t  messageLength,
const unsigned char *  signature,
const size_t  signatureLength 
)
static

Avoid Using Verify a message's signature using a raw libsodium verification key

Instead of using this static method, we recommend you use the seal method on an instance of a SignatureVerificationKey object.

Parameters
signatureVerificationKeyBytessignatureVerificationKeyBytes The raw key bytes
signatureVerificationKeyBytesLengthThe length of the raw key bytes
messageThe message that was signed
messageLengthThe length of the message that was signed
signatureThe signature generated by corresponding SigningKey when by calling SigningKey::generateSignature with the same message.
signatureLengthThe length of the signature
Returns
true if the signature is valid indicating the message was indeed signed by the corresponding SigningKey
false if the verification fails.

The documentation for this class was generated from the following files: