< prev index next >
src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -36,11 +36,13 @@
import javax.crypto.*;
import javax.crypto.interfaces.*;
import javax.crypto.spec.*;
+import sun.security.rsa.RSAUtil.KeyType;
import sun.security.rsa.RSAPublicKeyImpl;
+import sun.security.rsa.RSAPrivateCrtKeyImpl;
import sun.security.internal.interfaces.TlsMasterSecret;
import sun.security.pkcs11.wrapper.*;
import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
@@ -523,15 +525,12 @@
synchronized byte[] getEncodedInternal() {
token.ensureValid();
if (encoded == null) {
fetchValues();
try {
- // XXX make constructor in SunRsaSign provider public
- // and call it directly
- KeyFactory factory = KeyFactory.getInstance
- ("RSA", P11Util.getSunRsaSignProvider());
- Key newKey = factory.translateKey(this);
+ Key newKey = RSAPrivateCrtKeyImpl.newKey
+ (KeyType.RSA, null, n, e, d, p, q, pe, qe, coeff);
encoded = newKey.getEncoded();
} catch (GeneralSecurityException e) {
throw new ProviderException(e);
}
}
@@ -621,11 +620,10 @@
}
private static final class P11RSAPublicKey extends P11Key
implements RSAPublicKey {
private static final long serialVersionUID = -826726289023854455L;
-
private BigInteger n, e;
private byte[] encoded;
P11RSAPublicKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
super(PUBLIC, session, keyID, algorithm, keyLength, attributes);
@@ -650,11 +648,12 @@
synchronized byte[] getEncodedInternal() {
token.ensureValid();
if (encoded == null) {
fetchValues();
try {
- encoded = new RSAPublicKeyImpl(n, e).getEncoded();
+ encoded = RSAPublicKeyImpl.newKey
+ (KeyType.RSA, null, n, e).getEncoded();
} catch (InvalidKeyException e) {
throw new ProviderException(e);
}
}
return encoded;
< prev index next >