< prev index next >

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

Print this page




 398                     P11ECKeyFactory.encodeParameters((ECParameterSpec)params);
 399             publicKeyTemplate = new CK_ATTRIBUTE[] {
 400                 new CK_ATTRIBUTE(CKA_EC_PARAMS, encodedParams),
 401             };
 402             privateKeyTemplate = new CK_ATTRIBUTE[] {
 403                 // empty
 404             };
 405         } else {
 406             throw new ProviderException("Unknown algorithm: " + algorithm);
 407         }
 408         Session session = null;
 409         try {
 410             session = token.getObjSession();
 411             publicKeyTemplate = token.getAttributes
 412                 (O_GENERATE, CKO_PUBLIC_KEY, keyType, publicKeyTemplate);
 413             privateKeyTemplate = token.getAttributes
 414                 (O_GENERATE, CKO_PRIVATE_KEY, keyType, privateKeyTemplate);
 415             long[] keyIDs = token.p11.C_GenerateKeyPair
 416                 (session.id(), new CK_MECHANISM(mechanism),
 417                 publicKeyTemplate, privateKeyTemplate);
 418             PublicKey publicKey = P11Key.publicKey
 419                 (session, keyIDs[0], algorithm, keySize, publicKeyTemplate);
 420             PrivateKey privateKey = P11Key.privateKey
 421                 (session, keyIDs[1], algorithm, keySize, privateKeyTemplate);
 422             return new KeyPair(publicKey, privateKey);
 423         } catch (PKCS11Exception e) {
 424             throw new ProviderException(e);
 425         } finally {
 426             token.releaseSession(session);
 427         }
 428     }
 429 }


 398                     P11ECKeyFactory.encodeParameters((ECParameterSpec)params);
 399             publicKeyTemplate = new CK_ATTRIBUTE[] {
 400                 new CK_ATTRIBUTE(CKA_EC_PARAMS, encodedParams),
 401             };
 402             privateKeyTemplate = new CK_ATTRIBUTE[] {
 403                 // empty
 404             };
 405         } else {
 406             throw new ProviderException("Unknown algorithm: " + algorithm);
 407         }
 408         Session session = null;
 409         try {
 410             session = token.getObjSession();
 411             publicKeyTemplate = token.getAttributes
 412                 (O_GENERATE, CKO_PUBLIC_KEY, keyType, publicKeyTemplate);
 413             privateKeyTemplate = token.getAttributes
 414                 (O_GENERATE, CKO_PRIVATE_KEY, keyType, privateKeyTemplate);
 415             long[] keyIDs = token.p11.C_GenerateKeyPair
 416                 (session.id(), new CK_MECHANISM(mechanism),
 417                 publicKeyTemplate, privateKeyTemplate);
 418             PublicKey publicKey = P11Key.publicKey(session, keyIDs[0],
 419                     algorithm, keySize, publicKeyTemplate, true);
 420             PrivateKey privateKey = P11Key.privateKey(session, keyIDs[1],
 421                     algorithm, keySize, privateKeyTemplate, true);
 422             return new KeyPair(publicKey, privateKey);
 423         } catch (PKCS11Exception e) {
 424             throw new ProviderException(e);
 425         } finally {
 426             token.releaseSession(session);
 427         }
 428     }
 429 }
< prev index next >