8130007: Update security tests to use Security.getProvider to get security provider

Co-authored-by: Valerie Peng <valerie.peng@oracle.com>
Reviewed-by: mullan
This commit is contained in:
Mandy Chung 2015-06-29 11:38:36 -07:00
parent 24d0d5af7c
commit 1465e16631
28 changed files with 120 additions and 141 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2015, 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
@ -34,7 +34,6 @@ import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.Provider;
import com.sun.crypto.provider.*;
public class Test4511676 {
private static final String ALGO = "AES";
@ -59,7 +58,6 @@ public class Test4511676 {
}
public static void main (String[] args) throws Exception {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Test4511676 test = new Test4511676();
String testName = test.getClass().getName() + "[" + ALGO +

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2015, 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
@ -35,7 +35,6 @@ import java.util.Random;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.Provider;
import com.sun.crypto.provider.*;
public class Test4512524 {
@ -65,8 +64,6 @@ public class Test4512524 {
}
public static void main (String[] args) throws Exception {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Test4512524 test = new Test4512524();
test.execute("CBC");
test.execute("GCM");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2015, 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
@ -35,7 +35,6 @@ import java.util.Random;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.Provider;
import com.sun.crypto.provider.*;
public class Test4512704 {
private static final String ALGO = "AES";
@ -61,8 +60,6 @@ public class Test4512704 {
}
public static void main (String[] args) throws Exception {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Test4512704 test = new Test4512704();
test.execute("CBC");
test.execute("GCM");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2015, 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
@ -85,8 +85,6 @@ public class Test4513830 {
}
public static void main (String[] args) throws Exception {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Test4513830 test = new Test4513830();
String testName = test.getClass().getName() + "[" + ALGO +
"/" + MODE + "/" + PADDING + "]";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2015, 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
@ -37,7 +37,6 @@ import java.util.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.Provider;
import com.sun.crypto.provider.*;
public class Test4517355 {
@ -93,8 +92,6 @@ public class Test4517355 {
}
public static void main (String[] args) throws Exception {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Test4517355 test = new Test4517355();
Random rdm = new Random();
rdm.nextBytes(test.plainText);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2015, 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
@ -60,8 +60,6 @@ public class Test4626070 {
}
public static void main (String[] args) throws Exception {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Test4626070 test = new Test4626070();
test.execute("CBC", "PKCS5Padding");
test.execute("GCM", "NoPadding");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2015, 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
@ -118,8 +118,6 @@ public class TestKATForECB_IV
}
public static void main (String[] args) throws Exception {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
TestKATForECB_IV test = new TestKATForECB_IV();
String testName = test.getClass().getName() + "[" + ALGO +
"/" + MODE + "/" + PADDING + "]";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2015, 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
@ -34,7 +34,6 @@ import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.math.*;
import com.sun.crypto.provider.*;
import java.util.*;
@ -746,8 +745,6 @@ public class TestKATForECB_VK
}
public static void main (String[] args) throws Exception {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
TestKATForECB_VK test = new TestKATForECB_VK();
String testName = test.getClass().getName() + "[" + ALGO +
"/" + MODE + "/" + PADDING + "]";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2015, 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
@ -34,7 +34,6 @@ import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.math.*;
import com.sun.crypto.provider.*;
import java.util.*;
@ -555,8 +554,6 @@ public class TestKATForECB_VT
}
public static void main (String[] args) throws Exception {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
TestKATForECB_VT test = new TestKATForECB_VT();
String testName = test.getClass().getName() + "[" + ALGO +
"/" + MODE + "/" + PADDING + "]";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2015, 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
@ -68,10 +68,8 @@ public class BlowfishTestVector {
public static void main(String[] argv) throws Exception {
Provider p = new com.sun.crypto.provider.SunJCE();
Security.addProvider(p);
String transformation = "Blowfish/ECB/NoPadding";
Cipher cipher = Cipher.getInstance(transformation);
Cipher cipher = Cipher.getInstance(transformation, "SunJCE");
int MAX_KEY_SIZE = Cipher.getMaxAllowedKeyLength(transformation);
//
// test 1

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2015, 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
@ -46,11 +46,11 @@ public class DESSecretKeySpec {
System.out.println("Testing DES key");
SecretKeySpec skey = new SecretKeySpec(key, "DES");
c = Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE");
SecretKeyFactory.getInstance("DES").generateSecret(skey);
SecretKeyFactory.getInstance("DES", "SunJCE").generateSecret(skey);
System.out.println("Testing DESede key");
skey = new SecretKeySpec(key, "DESede");
c = Cipher.getInstance("DESede/CBC/PKCS5Padding", "SunJCE");
SecretKeyFactory.getInstance("TripleDES").generateSecret(skey);
SecretKeyFactory.getInstance("TripleDES", "SunJCE").generateSecret(skey);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2015, 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
@ -32,7 +32,6 @@ import java.security.*;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import com.sun.crypto.provider.*;
public class DesAPITest {
@ -87,9 +86,6 @@ public class DesAPITest {
public void init(String crypt, String mode, String padding)
throws Exception {
SunJCE jce = new SunJCE();
Security.addProvider(jce);
KeySpec desKeySpec = null;
SecretKeyFactory factory = null;
@ -99,7 +95,7 @@ public class DesAPITest {
if (padding.length() != 0)
cipherName.append("/" + padding);
cipher = Cipher.getInstance(cipherName.toString());
cipher = Cipher.getInstance(cipherName.toString(), "SunJCE");
if (crypt.endsWith("ede")) {
desKeySpec = new DESedeKeySpec(key3);
factory = SecretKeyFactory.getInstance("DESede", "SunJCE");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2015, 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
@ -85,9 +85,7 @@ public class DoFinalReturnLen {
IvParameterSpec IvParamSpec = null;
SecretKey sKey = null;
// Step 0: add providers
Provider sun = new com.sun.crypto.provider.SunJCE();
Security.addProvider(sun);
// Step 0: list providers
Provider[] theProviders = Security.getProviders();
for (int index = 0; index < theProviders.length; index++) {
System.out.println(theProviders[index].getName());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2015, 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
@ -32,18 +32,13 @@ import java.io.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import com.sun.crypto.provider.SunJCE;
public class FlushBug {
public static void main(String[] args) throws Exception {
Provider prov = new com.sun.crypto.provider.SunJCE();
Security.addProvider(prov);
SecureRandom sr = new SecureRandom();
// Create new DES key.
KeyGenerator kg = KeyGenerator.getInstance("DES");
KeyGenerator kg = KeyGenerator.getInstance("DES", "SunJCE");
kg.init(sr);
Key key = kg.generateKey();
@ -53,13 +48,13 @@ public class FlushBug {
IvParameterSpec iv = new IvParameterSpec(iv_bytes);
// Create the consumer
Cipher decrypter = Cipher.getInstance("DES/CFB8/NoPadding");
Cipher decrypter = Cipher.getInstance("DES/CFB8/NoPadding", "SunJCE");
decrypter.init(Cipher.DECRYPT_MODE, key, iv);
PipedInputStream consumer = new PipedInputStream();
InputStream in = new CipherInputStream(consumer, decrypter);
// Create the producer
Cipher encrypter = Cipher.getInstance("DES/CFB8/NoPadding");
Cipher encrypter = Cipher.getInstance("DES/CFB8/NoPadding", "SunJCE");
encrypter.init(Cipher.ENCRYPT_MODE, key, iv);
PipedOutputStream producer = new PipedOutputStream();
OutputStream out = new CipherOutputStream(producer, encrypter);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2015, 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
@ -118,7 +118,7 @@ public class PaddingTest {
if (padding.length() != 0)
cipherName.append("/" + padding);
cipher = Cipher.getInstance(cipherName.toString());
cipher = Cipher.getInstance(cipherName.toString(), "SunJCE");
if (crypt.endsWith("ede")) {
desKeySpec = new DESedeKeySpec(key3);
factory = SecretKeyFactory.getInstance("DESede", "SunJCE");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2015, 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
@ -152,7 +152,7 @@ public class PerformanceTest {
if (padding.length() != 0)
cipherName.append("/" + padding);
cipher = Cipher.getInstance(cipherName.toString());
cipher = Cipher.getInstance(cipherName.toString(), "SunJCE");
if (crypt.endsWith("ede")) {
desKeySpec = new DESedeKeySpec(key3);
factory = SecretKeyFactory.getInstance("DESede", "SunJCE");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2015, 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
@ -35,19 +35,17 @@ public class Sealtest {
public static void main(String[] args) throws Exception {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
// create DSA keypair
KeyPairGenerator kpgen = KeyPairGenerator.getInstance("DSA");
kpgen.initialize(512);
KeyPair kp = kpgen.generateKeyPair();
// create DES key
KeyGenerator kg = KeyGenerator.getInstance("DES");
KeyGenerator kg = KeyGenerator.getInstance("DES", "SunJCE");
SecretKey skey = kg.generateKey();
// create cipher
Cipher c = Cipher.getInstance("DES/CFB16/PKCS5Padding");
Cipher c = Cipher.getInstance("DES/CFB16/PKCS5Padding", "SunJCE");
c.init(Cipher.ENCRYPT_MODE, skey);
// seal the DSA private key

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2015, 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
@ -30,6 +30,7 @@
*/
import java.security.Security;
import java.security.Provider;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
@ -40,13 +41,12 @@ public class SunJCEGetInstance {
try{
// Remove SunJCE from Provider list
Provider prov = Security.getProvider("SunJCE");
Security.removeProvider("SunJCE");
// Create our own instance of SunJCE provider. Purposefully not
// using SunJCE.getInstance() so we can have our own instance
// for the test.
jce = Cipher.getInstance("AES/CBC/PKCS5Padding",
new com.sun.crypto.provider.SunJCE());
jce = Cipher.getInstance("AES/CBC/PKCS5Padding", prov);
jce.init(Cipher.ENCRYPT_MODE,
new SecretKeySpec("1234567890abcedf".getBytes(), "AES"));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2015, 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
@ -32,7 +32,6 @@ import java.security.spec.*;
import java.security.interfaces.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import com.sun.crypto.provider.*;
import java.math.BigInteger;
public class DHGenSharedSecret {
@ -69,8 +68,6 @@ public class DHGenSharedSecret {
};
public static void main(String[] args) throws Exception {
SunJCE jce = new SunJCE();
Security.addProvider(jce);
DHGenSharedSecret test = new DHGenSharedSecret();
test.run();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2015, 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
@ -25,6 +25,7 @@
* @test
* @bug 7146728
* @summary DHKeyAgreement2
* @modules java.base/sun.misc
* @author Jan Luehe
*/
@ -36,7 +37,6 @@ import java.security.interfaces.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
import com.sun.crypto.provider.SunJCE;
import sun.misc.HexDumpEncoder;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2015, 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
@ -36,7 +36,6 @@ import java.security.interfaces.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
import com.sun.crypto.provider.SunJCE;
/**
* This test utility executes the Diffie-Hellman key agreement protocol
@ -51,10 +50,6 @@ public class DHKeyAgreement3 {
private DHKeyAgreement3() {}
public static void main(String argv[]) throws Exception {
// Add JCE to the list of providers
SunJCE jce = new SunJCE();
Security.addProvider(jce);
DHKeyAgreement3 keyAgree = new DHKeyAgreement3();
keyAgree.run();
System.out.println("Test Passed");
@ -69,36 +64,36 @@ public class DHKeyAgreement3 {
// Alice creates her own DH key pair
System.err.println("ALICE: Generate DH keypair ...");
KeyPairGenerator aliceKpairGen = KeyPairGenerator.getInstance("DH");
KeyPairGenerator aliceKpairGen = KeyPairGenerator.getInstance("DH", "SunJCE");
aliceKpairGen.initialize(dhSkipParamSpec);
KeyPair aliceKpair = aliceKpairGen.generateKeyPair();
// Bob creates his own DH key pair
System.err.println("BOB: Generate DH keypair ...");
KeyPairGenerator bobKpairGen = KeyPairGenerator.getInstance("DH");
KeyPairGenerator bobKpairGen = KeyPairGenerator.getInstance("DH", "SunJCE");
bobKpairGen.initialize(dhSkipParamSpec);
KeyPair bobKpair = bobKpairGen.generateKeyPair();
// Carol creates her own DH key pair
System.err.println("CAROL: Generate DH keypair ...");
KeyPairGenerator carolKpairGen = KeyPairGenerator.getInstance("DH");
KeyPairGenerator carolKpairGen = KeyPairGenerator.getInstance("DH", "SunJCE");
carolKpairGen.initialize(dhSkipParamSpec);
KeyPair carolKpair = carolKpairGen.generateKeyPair();
// Alice initialize
System.err.println("ALICE: Initialize ...");
KeyAgreement aliceKeyAgree = KeyAgreement.getInstance("DH");
KeyAgreement aliceKeyAgree = KeyAgreement.getInstance("DH", "SunJCE");
aliceKeyAgree.init(aliceKpair.getPrivate());
// Bob initialize
System.err.println("BOB: Initialize ...");
KeyAgreement bobKeyAgree = KeyAgreement.getInstance("DH");
KeyAgreement bobKeyAgree = KeyAgreement.getInstance("DH", "SunJCE");
bobKeyAgree.init(bobKpair.getPrivate());
// Carol initialize
System.err.println("CAROL: Initialize ...");
KeyAgreement carolKeyAgree = KeyAgreement.getInstance("DH");
KeyAgreement carolKeyAgree = KeyAgreement.getInstance("DH", "SunJCE");
carolKeyAgree.init(carolKpair.getPrivate());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2015, 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
@ -36,7 +36,6 @@ import java.security.interfaces.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
import com.sun.crypto.provider.SunJCE;
/**
* This test creates a DH keypair, retrieves the encodings of the DH public and
@ -49,10 +48,6 @@ public class DHKeyFactory {
private DHKeyFactory() {}
public static void main(String argv[]) throws Exception {
// Add JCE to the list of providers
SunJCE jce = new SunJCE();
Security.addProvider(jce);
DHKeyFactory test = new DHKeyFactory();
test.run();
System.out.println("Test Passed");
@ -67,7 +62,7 @@ public class DHKeyFactory {
dhSkipParamSpec = new DHParameterSpec(skip1024Modulus,
skip1024Base);
KeyPairGenerator kpgen = KeyPairGenerator.getInstance("DH");
KeyPairGenerator kpgen = KeyPairGenerator.getInstance("DH", "SunJCE");
kpgen.initialize(dhSkipParamSpec);
KeyPair kp = kpgen.generateKeyPair();
@ -77,7 +72,7 @@ public class DHKeyFactory {
// get the private key encoding
byte[] privKeyEnc = kp.getPrivate().getEncoded();
KeyFactory kfac = KeyFactory.getInstance("DH");
KeyFactory kfac = KeyFactory.getInstance("DH", "SunJCE");
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(pubKeyEnc);
PublicKey pubKey = kfac.generatePublic(x509KeySpec);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2015, 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
@ -32,7 +32,6 @@ import java.security.spec.*;
import java.security.interfaces.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import com.sun.crypto.provider.*;
import java.math.*;
public class DHKeyGenSpeed {
@ -71,8 +70,6 @@ public class DHKeyGenSpeed {
};
public static void main(String[] args) throws Exception {
SunJCE jce = new SunJCE();
Security.addProvider(jce);
DHKeyGenSpeed test = new DHKeyGenSpeed();
test.run();
System.out.println("Test Passed");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2015, 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
@ -78,8 +78,6 @@ public class Test4628062 {
}
public static void main (String[] args) throws Exception {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Test4628062 test = new Test4628062();
String testName = test.getClass().getName();
if (test.execute("AES", AES_SIZES)) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, 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
@ -52,7 +52,6 @@ public class TestExplicitKeyLength {
}
public static void main (String[] args) throws Exception {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
for (int i = 0; i < ALGOS.length; i++) {
System.out.println("Testing " + ALGOS[i] + " KeyGenerator with " +
KEY_SIZES[i] + "-bit keysize");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2015, 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
@ -39,9 +39,6 @@ public class HmacMD5 {
int i, j, n;
Mac mac;
Provider jce = new com.sun.crypto.provider.SunJCE();
Security.addProvider(jce);
byte[][][] test_data = {
{
{ (byte)0x0b, (byte)0x0b, (byte)0x0b, (byte)0x0b,
@ -92,7 +89,7 @@ public class HmacMD5 {
}
};
mac = Mac.getInstance("HmacMD5");
mac = Mac.getInstance("HmacMD5", "SunJCE");
for (i=0; i<3; i++) {
j=0;
@ -109,7 +106,7 @@ public class HmacMD5 {
}
// now test multiple-part operation, using the 2nd test vector
mac = Mac.getInstance("HmacMD5");
mac = Mac.getInstance("HmacMD5", "SunJCE");
mac.init(new SecretKeySpec("Jefe".getBytes(), "HMAC"));
mac.update("what do ya ".getBytes());
mac.update("want for ".getBytes());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2015, 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
@ -35,7 +35,6 @@ import java.security.interfaces.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
import com.sun.crypto.provider.SunJCE;
/**
* Test that leading zeroes are stripped in TlsPremasterSecret case,
@ -52,10 +51,6 @@ public class TestLeadingZeroes {
private TestLeadingZeroes() {}
public static void main(String argv[]) throws Exception {
// Add JCE to the list of providers
SunJCE jce = new SunJCE();
Security.addProvider(jce);
TestLeadingZeroes keyAgree = new TestLeadingZeroes();
keyAgree.run();
System.out.println("Test Passed");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, 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
@ -348,96 +348,140 @@ public class EntryMethods
public static class Pre15 extends KeyStoreSpi {
private static KeyStoreSpi jks = getJKS();
private static KeyStore jks = getJKS();
// javac does not allow direct access to class (javac bug?)
// use reflection instead
private static KeyStoreSpi getJKS() {
private static KeyStore getJKS() {
try {
Class clazz = Class.forName("sun.security.provider.JavaKeyStore$JKS");
return (KeyStoreSpi)clazz.newInstance();
return (KeyStore) KeyStore.getInstance("JKS");
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public Pre15() {
}
public Key engineGetKey(String alias, char[] password)
throws NoSuchAlgorithmException, UnrecoverableKeyException {
return jks.engineGetKey(alias, password);
try {
return jks.getKey(alias, password);
} catch (KeyStoreException ke) {
throw new RuntimeException("Unexpected exception", ke);
}
}
public java.security.cert.Certificate[] engineGetCertificateChain
(String alias) {
return jks.engineGetCertificateChain(alias);
try {
return jks.getCertificateChain(alias);
} catch (KeyStoreException ke) {
throw new RuntimeException("Unexpected exception", ke);
}
}
public java.security.cert.Certificate engineGetCertificate
(String alias) {
return jks.engineGetCertificate(alias);
try {
return jks.getCertificate(alias);
} catch (KeyStoreException ke) {
throw new RuntimeException("Unexpected exception", ke);
}
}
public Date engineGetCreationDate(String alias) {
return jks.engineGetCreationDate(alias);
try {
return jks.getCreationDate(alias);
} catch (KeyStoreException ke) {
throw new RuntimeException("Unexpected exception", ke);
}
}
public void engineSetKeyEntry(String alias, Key key,
char[] password,
java.security.cert.Certificate[] chain)
throws KeyStoreException {
jks.engineSetKeyEntry(alias, key, password, chain);
jks.setKeyEntry(alias, key, password, chain);
}
public void engineSetKeyEntry(String alias, byte[] key,
java.security.cert.Certificate[] chain)
throws KeyStoreException {
jks.engineSetKeyEntry(alias, key, chain);
jks.setKeyEntry(alias, key, chain);
}
public void engineSetCertificateEntry(String alias,
java.security.cert.Certificate cert)
throws KeyStoreException {
jks.engineSetCertificateEntry(alias, cert);
jks.setCertificateEntry(alias, cert);
}
public void engineDeleteEntry(String alias)
throws KeyStoreException {
jks.engineDeleteEntry(alias);
jks.deleteEntry(alias);
}
public Enumeration engineAliases() {
return jks.engineAliases();
try {
return jks.aliases();
} catch (KeyStoreException ke) {
throw new RuntimeException("Unexpected exception", ke);
}
}
public boolean engineContainsAlias(String alias) {
return jks.engineContainsAlias(alias);
try {
return jks.containsAlias(alias);
} catch (KeyStoreException ke) {
throw new RuntimeException("Unexpected exception", ke);
}
}
public int engineSize() {
return jks.engineSize();
try {
return jks.size();
} catch (KeyStoreException ke) {
throw new RuntimeException("Unexpected exception", ke);
}
}
public boolean engineIsKeyEntry(String alias) {
return jks.engineIsKeyEntry(alias);
try {
return jks.isKeyEntry(alias);
} catch (KeyStoreException ke) {
throw new RuntimeException("Unexpected exception", ke);
}
}
public boolean engineIsCertificateEntry(String alias) {
return jks.engineIsCertificateEntry(alias);
try {
return jks.isCertificateEntry(alias);
} catch (KeyStoreException ke) {
throw new RuntimeException("Unexpected exception", ke);
}
}
public String engineGetCertificateAlias
(java.security.cert.Certificate cert) {
return jks.engineGetCertificateAlias(cert);
try {
return jks.getCertificateAlias(cert);
} catch (KeyStoreException ke) {
throw new RuntimeException("Unexpected exception", ke);
}
}
public void engineStore(OutputStream stream, char[] password)
throws IOException, NoSuchAlgorithmException, CertificateException {
jks.engineStore(stream, password);
try {
jks.store(stream, password);
} catch (KeyStoreException ke) {
throw new RuntimeException("Unexpected exception", ke);
}
}
public void engineLoad(InputStream stream, char[] password)
throws IOException, NoSuchAlgorithmException, CertificateException {
jks.engineLoad(stream, password);
jks.load(stream, password);
}
}