< prev index next >

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyGenerator.java

Print this page




 256             case (int)CKK_DES:
 257             case (int)CKK_DES2:
 258             case (int)CKK_DES3:
 259                 // fixed length, do not specify CKA_VALUE_LEN
 260                 attributes = new CK_ATTRIBUTE[] {
 261                     new CK_ATTRIBUTE(CKA_CLASS, CKO_SECRET_KEY),
 262                 };
 263                 break;
 264             default:
 265                 attributes = new CK_ATTRIBUTE[] {
 266                     new CK_ATTRIBUTE(CKA_CLASS, CKO_SECRET_KEY),
 267                     new CK_ATTRIBUTE(CKA_VALUE_LEN, keySize >> 3),
 268                 };
 269                 break;
 270             }
 271             attributes = token.getAttributes
 272                 (O_GENERATE, CKO_SECRET_KEY, keyType, attributes);
 273             long keyID = token.p11.C_GenerateKey
 274                 (session.id(), new CK_MECHANISM(mechanism), attributes);
 275             return P11Key.secretKey
 276                 (session, keyID, algorithm, significantKeySize, attributes);
 277         } catch (PKCS11Exception e) {
 278             throw new ProviderException("Could not generate key", e);
 279         } finally {
 280             token.releaseSession(session);
 281         }
 282     }
 283 
 284 }


 256             case (int)CKK_DES:
 257             case (int)CKK_DES2:
 258             case (int)CKK_DES3:
 259                 // fixed length, do not specify CKA_VALUE_LEN
 260                 attributes = new CK_ATTRIBUTE[] {
 261                     new CK_ATTRIBUTE(CKA_CLASS, CKO_SECRET_KEY),
 262                 };
 263                 break;
 264             default:
 265                 attributes = new CK_ATTRIBUTE[] {
 266                     new CK_ATTRIBUTE(CKA_CLASS, CKO_SECRET_KEY),
 267                     new CK_ATTRIBUTE(CKA_VALUE_LEN, keySize >> 3),
 268                 };
 269                 break;
 270             }
 271             attributes = token.getAttributes
 272                 (O_GENERATE, CKO_SECRET_KEY, keyType, attributes);
 273             long keyID = token.p11.C_GenerateKey
 274                 (session.id(), new CK_MECHANISM(mechanism), attributes);
 275             return P11Key.secretKey
 276                 (session, keyID, algorithm, significantKeySize, attributes, true);
 277         } catch (PKCS11Exception e) {
 278             throw new ProviderException("Could not generate key", e);
 279         } finally {
 280             token.releaseSession(session);
 281         }
 282     }
 283 
 284 }
< prev index next >