virgil_crypto package

Submodules

virgil_crypto.access_token_signer module

class virgil_crypto.access_token_signer.AccessTokenSigner(crypto=<virgil_crypto.crypto.VirgilCrypto object>)[source]

Bases: object

Access Token cryptographic signature operations Class provides a cryptographic signature operations for Access Token.

algorithm

Get Algorithm

crypto

Get Crypto

generate_token_signature(token, private_key)[source]

Generate signature for Access token :param token: Access Token. :param private_key: Signer Private Key.

Returns:Signature bytes.
verify_token_signature(signature, token, public_key)[source]

Verify Access Token signature :param signature: Token signature :param token: Access Token :param public_key: Signer Public Key

Returns:True if signature is valid, False otherwise.

virgil_crypto.card_crypto module

class virgil_crypto.card_crypto.CardCrypto(crypto=<virgil_crypto.crypto.VirgilCrypto object>)[source]

Bases: object

Cards cryptographic operations. Class provides a cryptographic operations for Cards.

crypto

Gets Virgil Crypto. :returns: Card Crypto

export_public_key(public_key)[source]

Exports the Public key into material representation. :param public_key: public key for export.

Returns:Key material representation bytes.
generate_sha512(data)[source]

Computes the sha512 hash of specified data. :param data: data bytes for fingerprint calculation.

Returns:Hash bytes.
generate_signature(data, private_key)[source]

Signs the specified data using Private key. :param data: raw data bytes for signing. :param private_key: private key for signing.

Returns:Signature bytes.
import_public_key(data)[source]

Imports the Public key from material representation. :param data: key material representation bytes.

Returns:Imported public key.
verify_signature(signature, data, public_key)[source]

Verifies the specified signature using original data and signer’s public key. :param data: original data bytes for verification. :param signature: signature bytes for verification. :param public_key: signer public key for verification.

Returns:True if signature is valid, False otherwise.

virgil_crypto.crypto module

class virgil_crypto.crypto.VirgilCrypto[source]

Bases: object

Wrapper for cryptographic operations.

Class provides a cryptographic operations in applications, such as hashing, signature generation and verification, and encryption and decryption

exception SignatureIsNotValid[source]

Bases: Exception

Exception raised when Signature is not valid

calculate_fingerprint(data)[source]

Calculates the fingerprint.

Parameters:data – data bytes for fingerprint calculation.
Returns:Fingerprint of the source data.
static compute_hash(data, algorithm)[source]

Computes the hash of specified data.

Parameters:
  • data – data bytes for fingerprint calculation.
  • algorithm – hashing algorithm. The possible values can be found in HashAlgorithm enum.
Returns:

Hash bytes.

compute_public_key_hash(public_key)[source]

Computes the hash of specified public key using SHA256 algorithm.

Parameters:public_key – public key for hashing.
Returns:Hash bytes.
custom_param_key_signature

Custom param key signature.

Returns:VIRGIL-DATA-SIGNATURE bytes.
static decrypt(cipher_data, private_key)[source]

Decrypts the specified data using Private key.

Parameters:
  • data – encrypted data bytes for decryption.
  • private_key – private key for decryption.
Returns:

Decrypted data bytes.

static decrypt_stream(input_stream, output_stream, private_key)[source]

Decrypts the specified stream using Private key.

Parameters:
  • input_stream – readable stream containing input data.
  • output_stream – writable stream for output.
  • private_key – private key for decryption.
decrypt_then_verify(data, private_key, public_key)[source]

Decrypts and verifies the data.

Parameters:
  • data – encrypted data bytes.
  • private_key – private key for decryption.
  • public_key – public key for verification.
Returns:

Decrypted data bytes.

Raises:

SignatureIsNotValid – if signature is not verified.

static encrypt(data, *recipients)[source]

Encrypts the specified data using recipients Public keys.

Parameters:
  • data – raw data bytes for encryption.
  • recipients – list of recipients’ public keys.
Returns:

Encrypted data bytes.

static encrypt_stream(input_stream, output_stream, *recipients)[source]

Encrypts the specified stream using recipients Public keys.

Parameters:
  • input_stream – readable stream containing input data.
  • output_stream – writable stream for output.
  • recipients – list of recipients’ public keys.
export_private_key(private_key, password=None)[source]

Exports the Private key into material representation.

Parameters:
  • private_key – private key for export.
  • password – private key password, None by default.
Returns:

Key material representation bytes.

static export_public_key(public_key)[source]

Exports the Public key into material representation.

Parameters:public_key – public key for export.
Returns:Key material representation bytes.
static extract_public_key(private_key)[source]

Extracts the Public key from Private key.

Parameters:private_key – source private key for extraction.
Returns:Exported public key.
generate_keys(key_pair_type=0)[source]

Generates asymmetric key pair that is comprised of both public and private keys by specified type.

Parameters:key_pair_type – type of the generated keys. The possible values can be found in KeyPairType enum.
Returns:Generated key pair.
import_private_key(key_data, password=None)[source]

Imports the Private key from material representation.

Parameters:
  • key_data – key material representation bytes.
  • password – private key password, None by default.
Returns:

Imported private key.

import_public_key(key_data)[source]

Imports the Public key from material representation.

Parameters:key_data – key material representation bytes.
Returns:Imported public key.
sign(data, private_key)[source]

Signs the specified data using Private key.

Parameters:
  • data – raw data bytes for signing.
  • private_key – private key for signing.
Returns:

Signature bytes.

sign_stream(input_stream, private_key)[source]

Signs the specified stream using Private key.

Parameters:
  • input_stream – readable stream containing input data.
  • private_key – private key for signing.
Returns:

Signature bytes.

sign_then_encrypt(data, private_key, *recipients)[source]

Signs and encrypts the data.

Parameters:
  • data – data bytes for signing and encryption.
  • private_key – private key to sign the data.
  • recipients – list of recipients’ public keys. Used for data encryption.
Returns:

Signed and encrypted data bytes.

static strtobytes(source)[source]

Convert string to bytes tuple used for all crypto methods.

Parameters:source – String for conversion.
Returns:Tuple containing bytes from converted source string.
verify(data, signature, signer_public_key)[source]

Verifies the specified signature using original data and signer’s public key.

Parameters:
  • data – original data bytes for verification.
  • signature – signature bytes for verification.
  • signer_public_key – signer public key for verification.
Returns:

True if signature is valid, False otherwise.

verify_stream(input_stream, signature, signer_public_key)[source]

Verifies the specified signature using original stream and signer’s Public key.

Parameters:
  • input_stream – readable stream containing input data.
  • signature – signature bytes for verification.
  • signer_public_key – signer public key for verification.
Returns:

True if signature is valid, False otherwise.

virgil_crypto.private_key_exporter module

class virgil_crypto.private_key_exporter.PrivateKeyExporter(password=None)[source]

Bases: object

PrivateKeyExporter provides a list of methods that lets user to export and import private key. :param password: The password for private key.

export_private_key(private_key)[source]

Exports the PrivateKey into material representation. If PrivateKeyExporter was instantiated with password then it will be used to export private key. :param private_key: The private key.

Returns:Private key in material representation of bytes.
import_private_key(key_data)[source]

Imports the private key from its material representation. If PrivateKeyExporter was instantiated with password then it will be used to import private key. :param key_data: The private key material representation bytes.

Returns:The instance of PrivateKey imported.

virgil_crypto.streams module

class virgil_crypto.streams.VirgilStreamDataSink(stream)[source]

Bases: virgil_crypto.virgil_crypto_python.VirgilDataSink

isGood()[source]
write(data)[source]
class virgil_crypto.streams.VirgilStreamDataSource(stream, buffer_size=1024)[source]

Bases: virgil_crypto.virgil_crypto_python.VirgilDataSource

hasData()[source]
read()[source]

Module contents