Class: Virgil::Crypto::VirgilCardCrypto

Inherits:
Object
  • Object
show all
Defined in:
lib/virgil/crypto/card_crypto.rb

Overview

Provides a cryptographic operations in applications, such as hashing, signature generation and verification, and encryption and decryption.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVirgilCardCrypto

Initializes a new instance of the [VirgilCardCrypto] class.



43
44
45
# File 'lib/virgil/crypto/card_crypto.rb', line 43

def initialize
  @virgil_crypto = VirgilCrypto.new
end

Instance Attribute Details

#virgil_cryptoObject (readonly)

Returns the value of attribute virgil_crypto.



40
41
42
# File 'lib/virgil/crypto/card_crypto.rb', line 40

def virgil_crypto
  @virgil_crypto
end

Instance Method Details

#export_public_key(public_key) ⇒ Crypto::Bytes

Exports the Public key into material representation.

Examples:

include Virgil::Crypto
crypto = VirgilCrypto.new
alice_keys = crypto.generate_keys
card_crypto = VirgilCardCrypto.new
exported_public_key = card_crypto.export_public_key(alice_keys.public_key)

Parameters:

Returns:



69
70
71
# File 'lib/virgil/crypto/card_crypto.rb', line 69

def export_public_key(public_key)
  @virgil_crypto.export_public_key(public_key)
end

#generate_SHA512(bytes) ⇒ Crypto::Bytes

Calculates the fingerprint.

Parameters:

Returns:



110
111
112
# File 'lib/virgil/crypto/card_crypto.rb', line 110

def generate_SHA512(bytes)
  @virgil_crypto.generate_hash(bytes)
end

#generate_signature(bytes, private_key) ⇒ Crypto::Bytes

Signs the specified data using Private key.

Examples:

Sign the fingerprint of bytes using your private key.

include Virgil::Crypto
crypto = VirgilCrypto.new
alice_keys = crypto.generate_keys()
# The data to be signed with alice's Private key
data = Bytes.from_string('Hello Bob, How are you?')
card_crypto = VirgilCardCrypto.new
signature = card_crypto.generate_signature(data, alice.private_key)

Parameters:

Returns:



85
86
87
# File 'lib/virgil/crypto/card_crypto.rb', line 85

def generate_signature(bytes, private_key)
  @virgil_crypto.generate_signature(bytes, private_key)
end

#import_public_key(key_bytes) ⇒ VirgilPublicKey

Imports the Public key from material representation. representation bytes.

Examples:

include Virgil::Crypto
card_crypto = VirgilCardCrypto.new
public_key = card_crypto.import_public_key(exported_public_key)

Parameters:

Returns:

See Also:



56
57
58
# File 'lib/virgil/crypto/card_crypto.rb', line 56

def import_public_key(key_bytes)
  @virgil_crypto.import_public_key(key_bytes)
end

#verify_signature(signature, bytes, signer_public_key) ⇒ Boolean

Verifies the specified signature using original data and signer's public key. key for verification. bytes using Public key.

include Virgil::Crypto
card_crypto = VirgilCardCrypto.new
public_key = crypto.import_public_key(exported_public_key)
data = Bytes.from_string('Hello Bob, How are you?')
is_valid = card_crypto.verify_signature(signature, data, public_key)

Examples:

Verify the signature of the fingerprint of

Parameters:

Returns:

  • (Boolean)

    True if signature is valid, False otherwise.



103
104
105
# File 'lib/virgil/crypto/card_crypto.rb', line 103

def verify_signature(signature, bytes, signer_public_key)
  @virgil_crypto.verify_signature(signature, bytes, signer_public_key)
end