Module crypto

Summary

Members Descriptions
namespacescy::crypto
structCRYPTO_dynlock_value

namespace scy::crypto

Summary

Members Descriptions
classscy::crypto::Cipher
classscy::crypto::Hash
classscy::crypto::X509Certificate This class represents a X509 Certificate.

class scy::crypto::Cipher

Provides symmetric algorithms for encryption and decryption. The algorithms that are available depend on the particular version of OpenSSL that is installed.

Summary

Members Descriptions
public Cipher(const std::string & name)
public Cipher(const std::string & name,constByteVec& key,constByteVec& iv)
public Cipher(const std::string & name,const std::string & passphrase,const std::string & salt,int iterationCount)
public ~Cipher() Destroys the Cipher.
public void initEncryptor() Initializes the Cipher for encryption.
public void initDecryptor() Initializes the Cipher for decryption.
public int update(const unsigned char * input,int inputLength,unsigned char * output,int outputLength)
public template<typename I,typename O>
inline int update(const I & input,O & output)
Alias for update() which accepts a range of buffer types.
public int final(unsigned char * output,int length)
public template<typename O>
inline int final(O & output)
Alias for final() which accepts a range of buffer types.
public int encrypt(const unsigned char * inbuf,std::size_t inlen,unsigned char * outbuf,std::size_t outlen,Encodingencoding)
public template<typename I,typename O>
inline int encrypt(const I & input,O & output,Encodingencoding)
Alias for encrypt() which accepts a range of buffer types.
public virtual std::string encryptString(const std::string & str,Encodingencoding) Encrypts a string and encodes it using the given encoding.
public virtual std::string decryptString(const std::string & str,Encodingencoding) Decrypts a string that is encoded with the given encoding.
public virtual void encryptStream(std::istream & source,std::ostream & sink,Encodingencoding) Encrypts an input stream and encodes it using the given encoding.
public virtual void decryptStream(std::istream & source,std::ostream & sink,Encodingencoding) Decrypts an input stream that is encoded with the given encoding.
public template<typename T>
inline void setKey(const T & key)
Sets the key for the Cipher.
public template<typename T>
inline void setIV(const T & iv)
Sets the initialization vector (IV) for the Cipher.
public int setPadding(int padding)
public constByteVec& getKey() const Returns the key for the Cipher.
public constByteVec& getIV() const Returns the initialization vector (IV) for the Cipher.
public const std::string & name() const Returns the name of the Cipher.
public int blockSize() const Returns the block size of the Cipher.
public int keySize() const Returns the key size of the Cipher.
public int ivSize() const Returns the IV size of the Cipher.
public const EVP_CIPHER * cipher() Returns the cipher object.
protected bool _initialized
protected bool _encrypt
protected const EVP_CIPHER * _cipher
protected std::string _name
protected EVP_CIPHER_CTX _ctx
protectedByteVec_key
protectedByteVec_iv
protected Cipher()
protected Cipher(constCipher&)
protectedCipher& operator=(constCipher&)
protected void generateKey(const std::string & passphrase,const std::string & salt,int iterationCount) Generates and sets the key and IV from a password and optional salt string.
protected void setRandomKey() Generates and sets key from random data.
protected void setRandomIV() Generates and sets IV from random data.
protected void initialize(bool encrypt) Initializes the Cipher using the given direction.

Members

public Cipher(const std::string & name)

Creates a new Cipher object. Auto initializes the key and initialization vector with random bytes.

public Cipher(const std::string & name,constByteVec& key,constByteVec& iv)

Creates a new Cipher object, using the given cipher name, key and initialization vector.

public Cipher(const std::string & name,const std::string & passphrase,const std::string & salt,int iterationCount)

Creates a new Cipher object, using the given cipher name, passphrase, salt value and iteration count.

public ~Cipher()

Destroys the Cipher.

public void initEncryptor()

Initializes the Cipher for encryption.

public void initDecryptor()

Initializes the Cipher for decryption.

public int update(const unsigned char * input,int inputLength,unsigned char * output,int outputLength)

Encrypts data in a streaming fashion. Hand consecutive blocks of data to the update method in order to encrypt it. Returns the encrypted data chunk. When done, the output of final() should be additionally added to the result.

public template<typename I,typename O>
inline int update(const I & input,O & output)

Alias for update() which accepts a range of buffer types.

public int final(unsigned char * output,int length)

Returns the remaining data held in the cipher object. Further calls to update() or final() will return garbage.

See EVP_CipherFinal_ex for further information.

public template<typename O>
inline int final(O & output)

Alias for final() which accepts a range of buffer types.

public int encrypt(const unsigned char * inbuf,std::size_t inlen,unsigned char * outbuf,std::size_t outlen,Encodingencoding)

Encrypts a buffer and encode it using the given encoding. This method performs the encryption, and calls final() internally.

public template<typename I,typename O>
inline int encrypt(const I & input,O & output,Encodingencoding)

Alias for encrypt() which accepts a range of buffer types.

public virtual std::string encryptString(const std::string & str,Encodingencoding)

Encrypts a string and encodes it using the given encoding.

public virtual std::string decryptString(const std::string & str,Encodingencoding)

Decrypts a string that is encoded with the given encoding.

public virtual void encryptStream(std::istream & source,std::ostream & sink,Encodingencoding)

Encrypts an input stream and encodes it using the given encoding.

public virtual void decryptStream(std::istream & source,std::ostream & sink,Encodingencoding)

Decrypts an input stream that is encoded with the given encoding.

public template<typename T>
inline void setKey(const T & key)

Sets the key for the Cipher.

public template<typename T>
inline void setIV(const T & iv)

Sets the initialization vector (IV) for the Cipher.

public int setPadding(int padding)

Enables or disables padding. By default encryption operations are padded using standard block padding and the padding is checked and removed when decrypting. If the pad parameter is zero then no padding is performed, the total amount of data encrypted or decrypted must then be a multiple of the block size or an error will occur.

See EVP_CIPHER_CTX_set_padding for further information.

public constByteVec& getKey() const

Returns the key for the Cipher.

public constByteVec& getIV() const

Returns the initialization vector (IV) for the Cipher.

public const std::string & name() const

Returns the name of the Cipher.

public int blockSize() const

Returns the block size of the Cipher.

public int keySize() const

Returns the key size of the Cipher.

public int ivSize() const

Returns the IV size of the Cipher.

public const EVP_CIPHER * cipher()

Returns the cipher object.

protected bool _initialized

protected bool _encrypt

protected const EVP_CIPHER * _cipher

protected std::string _name

protected EVP_CIPHER_CTX _ctx

protectedByteVec_key

protectedByteVec_iv

protected Cipher()

protected Cipher(constCipher&)

protectedCipher& operator=(constCipher&)

protected void generateKey(const std::string & passphrase,const std::string & salt,int iterationCount)

Generates and sets the key and IV from a password and optional salt string.

protected void setRandomKey()

Generates and sets key from random data.

protected void setRandomIV()

Generates and sets IV from random data.

protected void initialize(bool encrypt)

Initializes the Cipher using the given direction.

class scy::crypto::Hash

Summary

Members Descriptions
public Hash(const std::string & algorithm)
public ~Hash()
public void update(char data)
public void update(const std::string & data)
public void update(const void * data,unsigned length)
public constByteVec& digest() Finish up the digest operation and return the result.
public std::string digestStr() Finish up the digest operation and return the result as a string.
public void reset() Resets the engine and digest state ready for the next computation.
public const std::string & algorithm(void) const Returns the hash algorithm being used.
protected EVP_MD_CTX _ctx
protected const EVP_MD * _md
protectedcrypto::ByteVec_digest
protected std::string _algorithm
protectedHash& operator=(Hashconst &)

Members

public Hash(const std::string & algorithm)

public ~Hash()

public void update(char data)

public void update(const std::string & data)

public void update(const void * data,unsigned length)

This function may (and normally will) be called many times for large blocks of data.

public constByteVec& digest()

Finish up the digest operation and return the result.

public std::string digestStr()

Finish up the digest operation and return the result as a string.

public void reset()

Resets the engine and digest state ready for the next computation.

public const std::string & algorithm(void) const

Returns the hash algorithm being used.

protected EVP_MD_CTX _ctx

protected const EVP_MD * _md

protectedcrypto::ByteVec_digest

protected std::string _algorithm

protectedHash& operator=(Hashconst &)

class scy::crypto::X509Certificate

This class represents a X509 Certificate.

Summary

Members Descriptions
public explicit X509Certificate(const char * data,std::size_t length)
public explicit X509Certificate(const std::string & path)
public explicit X509Certificate(X509 * pCert)
public X509Certificate(X509 * pCert,bool shared)
public X509Certificate(constX509Certificate& cert) Creates the certificate by copying another one.
publicX509Certificate& operator=(constX509Certificate& cert) Assigns a certificate.
public void swap(X509Certificate& cert) Exchanges the certificate with another one.
public ~X509Certificate() Destroys the X509Certificate.
public const std::string & issuerName() const Returns the certificate issuer's distinguished name.
public std::string issuerName(NIDnid) const
public const std::string & subjectName() const Returns the certificate subject's distinguished name.
public std::string subjectName(NIDnid) const
public std::string commonName() const
public void extractNames(std::string & commonName,std::set< std::string > & domainNames) const
publicDateTimevalidFrom() const Returns the date and time the certificate is valid from.
publicDateTimeexpiresOn() const Returns the date and time the certificate expires.
public void save(std::ostream & stream) const
public void save(const std::string & path) const
public bool issuedBy(constX509Certificate& issuerCertificate) const
public const X509 * certificate() const Returns the underlying OpenSSL certificate.
protected void load(const char * data,std::size_t length)
protected void load(const std::string & path)
protected void init() Extracts issuer and subject name from the certificate.

Members

public explicit X509Certificate(const char * data,std::size_t length)

Creates the X509Certificate object by reading a certificate in PEM format from the given buffer.

public explicit X509Certificate(const std::string & path)

Creates the X509Certificate object by reading a certificate in PEM format from a file.

public explicit X509Certificate(X509 * pCert)

Creates the X509Certificate from an existing OpenSSL certificate. Ownership is taken of the certificate.

public X509Certificate(X509 * pCert,bool shared)

Creates the X509Certificate from an existing OpenSSL certificate. Ownership is taken of the certificate. If shared is true, the certificate's reference count is incremented.

public X509Certificate(constX509Certificate& cert)

Creates the certificate by copying another one.

publicX509Certificate& operator=(constX509Certificate& cert)

Assigns a certificate.

public void swap(X509Certificate& cert)

Exchanges the certificate with another one.

public ~X509Certificate()

Destroys the X509Certificate.

public const std::string & issuerName() const

Returns the certificate issuer's distinguished name.

public std::string issuerName(NIDnid) const

Extracts the information specified by the given NID (name identifier) from the certificate issuer's distinguished name.

public const std::string & subjectName() const

Returns the certificate subject's distinguished name.

public std::string subjectName(NIDnid) const

Extracts the information specified by the given NID (name identifier) from the certificate subject's distinguished name.

public std::string commonName() const

Returns the common name stored in the certificate subject's distinguished name.

public void extractNames(std::string & commonName,std::set< std::string > & domainNames) const

Extracts the common name and the alias domain names from the certificate.

publicDateTimevalidFrom() const

Returns the date and time the certificate is valid from.

publicDateTimeexpiresOn() const

Returns the date and time the certificate expires.

public void save(std::ostream & stream) const

Writes the certificate to the given stream. The certificate is written in PEM format.

public void save(const std::string & path) const

Writes the certificate to the file given by path. The certificate is written in PEM format.

public bool issuedBy(constX509Certificate& issuerCertificate) const

Checks whether the certificate has been issued by the issuer given by issuerCertificate. This can be used to validate a certificate chain.

Verifies if the certificate has been signed with the issuer's private key, using the public key from the issuer certificate.

Returns true if verification against the issuer certificate was successful, false otherwise.

public const X509 * certificate() const

Returns the underlying OpenSSL certificate.

protected void load(const char * data,std::size_t length)

Loads the certificate from the given buffer. The certificate must be in PEM format.

protected void load(const std::string & path)

Loads the certificate from the given file. The certificate must be in PEM format.

protected void init()

Extracts issuer and subject name from the certificate.

struct CRYPTO_dynlock_value

Summary

Members Descriptions
publicscy::Mutex_mutex

Members

publicscy::Mutex_mutex

results matching ""

    No results matching ""