sun.security.jca.JCAUtil Java Examples
The following examples show how to use
sun.security.jca.JCAUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageDigestSpi.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Update the digest using the specified ByteBuffer. The digest is * updated using the {@code input.remaining()} bytes starting * at {@code input.position()}. * Upon return, the buffer's position will be equal to its limit; * its limit will not have changed. * * @param input the ByteBuffer * @since 1.5 */ protected void engineUpdate(ByteBuffer input) { if (input.hasRemaining() == false) { return; } if (input.hasArray()) { byte[] b = input.array(); int ofs = input.arrayOffset(); int pos = input.position(); int lim = input.limit(); engineUpdate(b, ofs + pos, lim - pos); input.position(lim); } else { int len = input.remaining(); int n = JCAUtil.getTempArraySize(len); if ((tempArray == null) || (n > tempArray.length)) { tempArray = new byte[n]; } while (len > 0) { int chunk = Math.min(len, tempArray.length); input.get(tempArray, 0, chunk); engineUpdate(tempArray, 0, chunk); len -= chunk; } } }
Example #2
Source File: DSAKeyPairGenerator.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Generates a pair of keys usable by any JavaSecurity compliant * DSA implementation. */ public KeyPair generateKeyPair() { if (random == null) { random = JCAUtil.getSecureRandom(); } DSAParameterSpec spec; try { if (forceNewParameters) { // generate new parameters each time spec = ParameterCache.getNewDSAParameterSpec(plen, qlen, random); } else { if (params == null) { params = ParameterCache.getDSAParameterSpec(plen, qlen, random); } spec = params; } } catch (GeneralSecurityException e) { throw new ProviderException(e); } return generateKeyPair(spec.getP(), spec.getQ(), spec.getG(), random); }
Example #3
Source File: DSAKeyPairGenerator.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Generates a pair of keys usable by any JavaSecurity compliant * DSA implementation. */ public KeyPair generateKeyPair() { if (random == null) { random = JCAUtil.getSecureRandom(); } DSAParameterSpec spec; try { if (forceNewParameters) { // generate new parameters each time spec = ParameterCache.getNewDSAParameterSpec(plen, qlen, random); } else { if (params == null) { params = ParameterCache.getDSAParameterSpec(plen, qlen, random); } spec = params; } } catch (GeneralSecurityException e) { throw new ProviderException(e); } return generateKeyPair(spec.getP(), spec.getQ(), spec.getG(), random); }
Example #4
Source File: ECKeyPairGenerator.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Override public KeyPair generateKeyPair() { if (random == null) { random = JCAUtil.getSecureRandom(); } try { Optional<KeyPair> kp = generateKeyPairImpl(random); if (kp.isPresent()) { return kp.get(); } return generateKeyPairNative(random); } catch (Exception ex) { throw new ProviderException(ex); } }
Example #5
Source File: DSAKeyPairGenerator.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Generates a pair of keys usable by any JavaSecurity compliant * DSA implementation. */ public KeyPair generateKeyPair() { if (random == null) { random = JCAUtil.getSecureRandom(); } DSAParameterSpec spec; try { if (forceNewParameters) { // generate new parameters each time spec = ParameterCache.getNewDSAParameterSpec(plen, qlen, random); } else { if (params == null) { params = ParameterCache.getDSAParameterSpec(plen, qlen, random); } spec = params; } } catch (GeneralSecurityException e) { throw new ProviderException(e); } return generateKeyPair(spec.getP(), spec.getQ(), spec.getG(), random); }
Example #6
Source File: ECDSASignature.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override protected byte[] engineSign() throws SignatureException { byte[] s = privateKey.getS().toByteArray(); ECParameterSpec params = privateKey.getParams(); // DER OID byte[] encodedParams = ECUtil.encodeECParameterSpec(null, params); int keySize = params.getCurve().getField().getFieldSize(); // seed is twice the key size (in bytes) plus 1 byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2]; if (random == null) { random = JCAUtil.getSecureRandom(); } random.nextBytes(seed); try { return encodeSignature( signDigest(getDigestValue(), s, encodedParams, seed)); } catch (GeneralSecurityException e) { throw new SignatureException("Could not sign data", e); } }
Example #7
Source File: DSAKeyPairGenerator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Generates a pair of keys usable by any JavaSecurity compliant * DSA implementation. */ public KeyPair generateKeyPair() { if (random == null) { random = JCAUtil.getSecureRandom(); } DSAParameterSpec spec; try { if (forceNewParameters) { // generate new parameters each time spec = ParameterCache.getNewDSAParameterSpec(plen, qlen, random); } else { if (params == null) { params = ParameterCache.getDSAParameterSpec(plen, qlen, random); } spec = params; } } catch (GeneralSecurityException e) { throw new ProviderException(e); } return generateKeyPair(spec.getP(), spec.getQ(), spec.getG(), random); }
Example #8
Source File: MessageDigestSpi.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Update the digest using the specified ByteBuffer. The digest is * updated using the {@code input.remaining()} bytes starting * at {@code input.position()}. * Upon return, the buffer's position will be equal to its limit; * its limit will not have changed. * * @param input the ByteBuffer * @since 1.5 */ protected void engineUpdate(ByteBuffer input) { if (input.hasRemaining() == false) { return; } if (input.hasArray()) { byte[] b = input.array(); int ofs = input.arrayOffset(); int pos = input.position(); int lim = input.limit(); engineUpdate(b, ofs + pos, lim - pos); input.position(lim); } else { int len = input.remaining(); int n = JCAUtil.getTempArraySize(len); if ((tempArray == null) || (n > tempArray.length)) { tempArray = new byte[n]; } while (len > 0) { int chunk = Math.min(len, tempArray.length); input.get(tempArray, 0, chunk); engineUpdate(tempArray, 0, chunk); len -= chunk; } } }
Example #9
Source File: MessageDigestSpi.java From jdk-1.7-annotated with Apache License 2.0 | 6 votes |
/** * Update the digest using the specified ByteBuffer. The digest is * updated using the <code>input.remaining()</code> bytes starting * at <code>input.position()</code>. * Upon return, the buffer's position will be equal to its limit; * its limit will not have changed. * * @param input the ByteBuffer * @since 1.5 */ protected void engineUpdate(ByteBuffer input) { if (input.hasRemaining() == false) { return; } if (input.hasArray()) { byte[] b = input.array(); int ofs = input.arrayOffset(); int pos = input.position(); int lim = input.limit(); engineUpdate(b, ofs + pos, lim - pos); input.position(lim); } else { int len = input.remaining(); int n = JCAUtil.getTempArraySize(len); if ((tempArray == null) || (n > tempArray.length)) { tempArray = new byte[n]; } while (len > 0) { int chunk = Math.min(len, tempArray.length); input.get(tempArray, 0, chunk); engineUpdate(tempArray, 0, chunk); len -= chunk; } } }
Example #10
Source File: DSAKeyPairGenerator.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Generates a pair of keys usable by any JavaSecurity compliant * DSA implementation. */ public KeyPair generateKeyPair() { if (random == null) { random = JCAUtil.getSecureRandom(); } DSAParameterSpec spec; try { if (forceNewParameters) { // generate new parameters each time spec = ParameterCache.getNewDSAParameterSpec(plen, qlen, random); } else { if (params == null) { params = ParameterCache.getDSAParameterSpec(plen, qlen, random); } spec = params; } } catch (GeneralSecurityException e) { throw new ProviderException(e); } return generateKeyPair(spec.getP(), spec.getQ(), spec.getG(), random); }
Example #11
Source File: ECDSASignature.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override protected byte[] engineSign() throws SignatureException { if (random == null) { random = JCAUtil.getSecureRandom(); } byte[] digest = getDigestValue(); Optional<byte[]> sigOpt = signDigestImpl(privateKey, digest, random); byte[] sig; if (sigOpt.isPresent()) { sig = sigOpt.get(); } else { sig = signDigestNative(privateKey, digest, random); } return encodeSignature(sig); }
Example #12
Source File: DSAKeyPairGenerator.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Generates a pair of keys usable by any JavaSecurity compliant * DSA implementation. */ public KeyPair generateKeyPair() { if (random == null) { random = JCAUtil.getSecureRandom(); } DSAParameterSpec spec; try { if (forceNewParameters) { // generate new parameters each time spec = ParameterCache.getNewDSAParameterSpec(plen, qlen, random); } else { if (params == null) { params = ParameterCache.getDSAParameterSpec(plen, qlen, random); } spec = params; } } catch (GeneralSecurityException e) { throw new ProviderException(e); } return generateKeyPair(spec.getP(), spec.getQ(), spec.getG(), random); }
Example #13
Source File: DSAKeyPairGenerator.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Generates a pair of keys usable by any JavaSecurity compliant * DSA implementation. */ public KeyPair generateKeyPair() { if (random == null) { random = JCAUtil.getSecureRandom(); } DSAParameterSpec spec; try { if (forceNewParameters) { // generate new parameters each time spec = ParameterCache.getNewDSAParameterSpec(plen, qlen, random); } else { if (params == null) { params = ParameterCache.getDSAParameterSpec(plen, qlen, random); } spec = params; } } catch (GeneralSecurityException e) { throw new ProviderException(e); } return generateKeyPair(spec.getP(), spec.getQ(), spec.getG(), random); }
Example #14
Source File: MessageDigestSpi.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Update the digest using the specified ByteBuffer. The digest is * updated using the {@code input.remaining()} bytes starting * at {@code input.position()}. * Upon return, the buffer's position will be equal to its limit; * its limit will not have changed. * * @param input the ByteBuffer * @since 1.5 */ protected void engineUpdate(ByteBuffer input) { if (input.hasRemaining() == false) { return; } if (input.hasArray()) { byte[] b = input.array(); int ofs = input.arrayOffset(); int pos = input.position(); int lim = input.limit(); engineUpdate(b, ofs + pos, lim - pos); input.position(lim); } else { int len = input.remaining(); int n = JCAUtil.getTempArraySize(len); if ((tempArray == null) || (n > tempArray.length)) { tempArray = new byte[n]; } while (len > 0) { int chunk = Math.min(len, tempArray.length); input.get(tempArray, 0, chunk); engineUpdate(tempArray, 0, chunk); len -= chunk; } } }
Example #15
Source File: ECKeyPairGenerator.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Override public KeyPair generateKeyPair() { if (random == null) { random = JCAUtil.getSecureRandom(); } try { Optional<KeyPair> kp = generateKeyPairImpl(random); if (kp.isPresent()) { return kp.get(); } return generateKeyPairNative(random); } catch (Exception ex) { throw new ProviderException(ex); } }
Example #16
Source File: MessageDigestSpi.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Update the digest using the specified ByteBuffer. The digest is * updated using the {@code input.remaining()} bytes starting * at {@code input.position()}. * Upon return, the buffer's position will be equal to its limit; * its limit will not have changed. * * @param input the ByteBuffer * @since 1.5 */ protected void engineUpdate(ByteBuffer input) { if (input.hasRemaining() == false) { return; } if (input.hasArray()) { byte[] b = input.array(); int ofs = input.arrayOffset(); int pos = input.position(); int lim = input.limit(); engineUpdate(b, ofs + pos, lim - pos); input.position(lim); } else { int len = input.remaining(); int n = JCAUtil.getTempArraySize(len); if ((tempArray == null) || (n > tempArray.length)) { tempArray = new byte[n]; } while (len > 0) { int chunk = Math.min(len, tempArray.length); input.get(tempArray, 0, chunk); engineUpdate(tempArray, 0, chunk); len -= chunk; } } }
Example #17
Source File: ECDSASignature.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Override protected byte[] engineSign() throws SignatureException { if (random == null) { random = JCAUtil.getSecureRandom(); } byte[] digest = getDigestValue(); Optional<byte[]> sigOpt = signDigestImpl(privateKey, digest, random); byte[] sig; if (sigOpt.isPresent()) { sig = sigOpt.get(); } else { sig = signDigestNative(privateKey, digest, random); } return ECUtil.encodeSignature(sig); }
Example #18
Source File: ECDSASignature.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override protected byte[] engineSign() throws SignatureException { byte[] s = privateKey.getS().toByteArray(); ECParameterSpec params = privateKey.getParams(); // DER OID byte[] encodedParams = ECUtil.encodeECParameterSpec(null, params); int keySize = params.getCurve().getField().getFieldSize(); // seed is twice the key size (in bytes) plus 1 byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2]; if (random == null) { random = JCAUtil.getSecureRandom(); } random.nextBytes(seed); try { return encodeSignature( signDigest(getDigestValue(), s, encodedParams, seed)); } catch (GeneralSecurityException e) { throw new SignatureException("Could not sign data", e); } }
Example #19
Source File: ECKeyPairGenerator.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public KeyPair generateKeyPair() { if (random == null) { random = JCAUtil.getSecureRandom(); } try { Optional<KeyPair> kp = generateKeyPairImpl(random); if (kp.isPresent()) { return kp.get(); } return generateKeyPairNative(random); } catch (Exception ex) { throw new ProviderException(ex); } }
Example #20
Source File: DSAKeyPairGenerator.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Generates a pair of keys usable by any JavaSecurity compliant * DSA implementation. */ public KeyPair generateKeyPair() { if (random == null) { random = JCAUtil.getSecureRandom(); } DSAParameterSpec spec; try { if (forceNewParameters) { // generate new parameters each time spec = ParameterCache.getNewDSAParameterSpec(plen, qlen, random); } else { if (params == null) { params = ParameterCache.getDSAParameterSpec(plen, qlen, random); } spec = params; } } catch (GeneralSecurityException e) { throw new ProviderException(e); } return generateKeyPair(spec.getP(), spec.getQ(), spec.getG(), random); }
Example #21
Source File: MessageDigestSpi.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * Update the digest using the specified ByteBuffer. The digest is * updated using the {@code input.remaining()} bytes starting * at {@code input.position()}. * Upon return, the buffer's position will be equal to its limit; * its limit will not have changed. * * @param input the ByteBuffer * @since 1.5 */ protected void engineUpdate(ByteBuffer input) { if (input.hasRemaining() == false) { return; } if (input.hasArray()) { byte[] b = input.array(); int ofs = input.arrayOffset(); int pos = input.position(); int lim = input.limit(); engineUpdate(b, ofs + pos, lim - pos); input.position(lim); } else { int len = input.remaining(); int n = JCAUtil.getTempArraySize(len); if ((tempArray == null) || (n > tempArray.length)) { tempArray = new byte[n]; } while (len > 0) { int chunk = Math.min(len, tempArray.length); input.get(tempArray, 0, chunk); engineUpdate(tempArray, 0, chunk); len -= chunk; } } }
Example #22
Source File: ECDSASignature.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override protected byte[] engineSign() throws SignatureException { if (random == null) { random = JCAUtil.getSecureRandom(); } byte[] digest = getDigestValue(); Optional<byte[]> sigOpt = signDigestImpl(privateKey, digest, random); byte[] sig; if (sigOpt.isPresent()) { sig = sigOpt.get(); } else { sig = signDigestNative(privateKey, digest, random); } return ECUtil.encodeSignature(sig); }
Example #23
Source File: MessageDigestSpi.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Update the digest using the specified ByteBuffer. The digest is * updated using the {@code input.remaining()} bytes starting * at {@code input.position()}. * Upon return, the buffer's position will be equal to its limit; * its limit will not have changed. * * @param input the ByteBuffer * @since 1.5 */ protected void engineUpdate(ByteBuffer input) { if (input.hasRemaining() == false) { return; } if (input.hasArray()) { byte[] b = input.array(); int ofs = input.arrayOffset(); int pos = input.position(); int lim = input.limit(); engineUpdate(b, ofs + pos, lim - pos); input.position(lim); } else { int len = input.remaining(); int n = JCAUtil.getTempArraySize(len); if ((tempArray == null) || (n > tempArray.length)) { tempArray = new byte[n]; } while (len > 0) { int chunk = Math.min(len, tempArray.length); input.get(tempArray, 0, chunk); engineUpdate(tempArray, 0, chunk); len -= chunk; } } }
Example #24
Source File: DSAKeyPairGenerator.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * Generates a pair of keys usable by any JavaSecurity compliant * DSA implementation. */ public KeyPair generateKeyPair() { if (random == null) { random = JCAUtil.getSecureRandom(); } DSAParameterSpec spec; try { if (forceNewParameters) { // generate new parameters each time spec = ParameterCache.getNewDSAParameterSpec(plen, qlen, random); } else { if (params == null) { params = ParameterCache.getDSAParameterSpec(plen, qlen, random); } spec = params; } } catch (GeneralSecurityException e) { throw new ProviderException(e); } return generateKeyPair(spec.getP(), spec.getQ(), spec.getG(), random); }
Example #25
Source File: DSA.java From Bytecoder with Apache License 2.0 | 5 votes |
protected SecureRandom getSigningRandom() { if (signingRandom == null) { if (appRandom != null) { signingRandom = appRandom; } else { signingRandom = JCAUtil.getSecureRandom(); } } return signingRandom; }
Example #26
Source File: DSA.java From hottub with GNU General Public License v2.0 | 5 votes |
protected SecureRandom getSigningRandom() { if (signingRandom == null) { if (appRandom != null) { signingRandom = appRandom; } else { signingRandom = JCAUtil.getSecureRandom(); } } return signingRandom; }
Example #27
Source File: Token.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private synchronized byte[] getTokenId() { if (tokenId == null) { SecureRandom random = JCAUtil.getSecureRandom(); tokenId = new byte[20]; random.nextBytes(tokenId); serializedTokens.add(new WeakReference<Token>(this)); } return tokenId; }
Example #28
Source File: RSAPSSSignature.java From Bytecoder with Apache License 2.0 | 5 votes |
@Override protected void engineInitSign(PrivateKey privateKey, SecureRandom random) throws InvalidKeyException { if (!(privateKey instanceof RSAPrivateKey)) { throw new InvalidKeyException("key must be RSAPrivateKey"); } this.privKey = (RSAPrivateKey) isValid((RSAKey)privateKey); this.pubKey = null; this.random = (random == null? JCAUtil.getSecureRandom() : random); resetDigest(); }
Example #29
Source File: DSA.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
protected SecureRandom getSigningRandom() { if (signingRandom == null) { if (appRandom != null) { signingRandom = appRandom; } else { signingRandom = JCAUtil.getSecureRandom(); } } return signingRandom; }
Example #30
Source File: Token.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
boolean supportsRawSecretKeyImport() { if (supportsRawSecretKeyImport == null) { SecureRandom random = JCAUtil.getSecureRandom(); byte[] encoded = new byte[48]; random.nextBytes(encoded); CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[3]; attributes[0] = new CK_ATTRIBUTE(CKA_CLASS, CKO_SECRET_KEY); attributes[1] = new CK_ATTRIBUTE(CKA_KEY_TYPE, CKK_GENERIC_SECRET); attributes[2] = new CK_ATTRIBUTE(CKA_VALUE, encoded); Session session = null; try { attributes = getAttributes(O_IMPORT, CKO_SECRET_KEY, CKK_GENERIC_SECRET, attributes); session = getObjSession(); long keyID = p11.C_CreateObject(session.id(), attributes); supportsRawSecretKeyImport = Boolean.TRUE; } catch (PKCS11Exception e) { supportsRawSecretKeyImport = Boolean.FALSE; } finally { releaseSession(session); } } return supportsRawSecretKeyImport; }