Skip to content

Instantly share code, notes, and snippets.

@keithballdotnet
Created February 13, 2015 07:45
Show Gist options
  • Save keithballdotnet/a379b1d61a6e7e717f26 to your computer and use it in GitHub Desktop.
Save keithballdotnet/a379b1d61a6e7e717f26 to your computer and use it in GitHub Desktop.
aesKeyTemplate := []*pkcs11.Attribute{
pkcs11.NewAttribute(pkcs11.CKA_CLASS, pkcs11.CKO_SECRET_KEY),
pkcs11.NewAttribute(pkcs11.CKA_KEY_TYPE, pkcs11.CKK_AES),
pkcs11.NewAttribute(pkcs11.CKA_ENCRYPT, true),
pkcs11.NewAttribute(pkcs11.CKA_DECRYPT, true),
pkcs11.NewAttribute(pkcs11.CKA_SIGN, true),
pkcs11.NewAttribute(pkcs11.CKA_VERIFY, true),
pkcs11.NewAttribute(pkcs11.CKA_TOKEN, true),
pkcs11.NewAttribute(pkcs11.CKA_PRIVATE, false),
pkcs11.NewAttribute(pkcs11.CKA_VALUE, 16), /* KeyLength */
pkcs11.NewAttribute(pkcs11.CKA_LABEL, "My First AES Key"), /* Name of Key */
}
aesKey, err := p.CreateObject(session, aesKeyTemplate)
//aesKey, err := p.GenerateKey(session, []*pkcs11.Mechanism{pkcs11.NewMechanism(pkcs11.CKM_AES_KEY_GEN, nil)}, aesKeyTemplate)
if err != nil {
panic(fmt.Sprintf("GenerateKey() failed %s\n", err))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment