Method: PKCS11::Session#C_CreateObject

Defined in:
lib/pkcs11/session.rb

#C_CreateObject(template = {}) ⇒ PKCS11::Object Also known as: create_object

Creates a new Object based on given template.

If #C_CreateObject is used to create a key object, the key object will have its CKA_LOCAL attribute set to false. If that key object is a secret or private key then the new key will have the CKA_ALWAYS_SENSITIVE attribute set to false, and the CKA_NEVER_EXTRACTABLE attribute set to false.

Only session objects can be created during a read-only session. Only public objects can be created unless the normal user is logged in.

Examples:

Creating a 112 bit DES key from plaintext

secret_key = session.create_object(
  CLASS: PKCS11::CKO_SECRET_KEY, KEY_TYPE: PKCS11::CKK_DES2,
  ENCRYPT: true, WRAP: true, DECRYPT: true, UNWRAP: true,
  VALUE: '0123456789abcdef', LABEL: 'test_secret_key')

Parameters:

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

    Attributes of the object to create.

Returns:



152
153
154
155
# File 'lib/pkcs11/session.rb', line 152

def C_CreateObject(template={})
  handle = @pk.C_CreateObject(@sess, to_attributes(template))
  Object.new @pk, @sess, handle
end