public ObjectHandle UnwrapKey(Mechanism mechanism, ObjectHandle unwrappingKeyHandle, byte[] wrappedKey, List<ObjectAttribute> attributes)
{
if (this._disposed)
throw new ObjectDisposedException(this.GetType().FullName);
if (mechanism == null)
throw new ArgumentNullException("mechanism");
if (unwrappingKeyHandle == null)
throw new ArgumentNullException("unwrappingKeyHandle");
if (wrappedKey == null)
throw new ArgumentNullException("wrappedKey");
CK_MECHANISM ckMechanism = mechanism.CkMechanism;
CK_ATTRIBUTE[] template = null;
ulong templateLen = 0;
if (attributes != null)
{
template = new CK_ATTRIBUTE[attributes.Count];
for (int i = 0; i < attributes.Count; i++)
template[i] = attributes[i].CkAttribute;
templateLen = Convert.ToUInt64(attributes.Count);
}
ulong unwrappedKey = CK.CK_INVALID_HANDLE;
CKR rv = _p11.C_UnwrapKey(_sessionId, ref ckMechanism, unwrappingKeyHandle.ObjectId, wrappedKey, Convert.ToUInt64(wrappedKey.Length), template, templateLen, ref unwrappedKey);
if (rv != CKR.CKR_OK)
throw new Pkcs11Exception("C_UnwrapKey", rv);
return new ObjectHandle(unwrappedKey);
}