Method: PKCS11::Session#C_GenerateKeyPair

Defined in:
lib/pkcs11/session.rb

#C_GenerateKeyPair(mechanism, pubkey_template = {}, privkey_template = {}) ⇒ Array<PKCS11::Object> Also known as: generate_key_pair

Generates a public/private key pair, creating new key Object instances.

Examples:

pub_key, priv_key = session.generate_key_pair(:RSA_PKCS_KEY_PAIR_GEN,
  {ENCRYPT: true, VERIFY: true, WRAP: true, MODULUS_BITS: 768, PUBLIC_EXPONENT: 3},
  {SUBJECT: 'test', ID: "ID", DECRYPT: true, SIGN: true, UNWRAP: true})

Parameters:

  • mechanism (Hash, Symbol, Integer, PKCS11::CK_MECHANISM)

    used mechanism

  • pubkey_template (Hash) (defaults to: {})

    Attributes of the public key to create.

  • privkey_template (Hash) (defaults to: {})

    Attributes of the private key to create.

Returns:

  • (Array<PKCS11::Object>)

    an two-items array of new created public and private key Object.


669
670
671
672
# File 'lib/pkcs11/session.rb', line 669

def C_GenerateKeyPair(mechanism, pubkey_template={}, privkey_template={})
  objs = @pk.C_GenerateKeyPair(@sess, to_mechanism(mechanism), to_attributes(pubkey_template), to_attributes(privkey_template))
  objs.map{|obj| Object.new @pk, @sess, obj }
end