--- a/jdk/test/sun/security/pkcs11/Secmod/GetPrivateKey.java Mon Sep 14 19:49:28 2015 +0300
+++ b/jdk/test/sun/security/pkcs11/Secmod/GetPrivateKey.java Mon Sep 14 19:54:58 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -24,11 +24,11 @@
/**
* @test
* @bug 6273877 6322208 6275523
- * @summary make sure we can access the NSS softtoken KeyStore and use a private key
+ * @summary make sure we can access the NSS softtoken KeyStore
+ * and use a private key
* @author Andreas Sterbenz
* @library ..
* @run main/othervm GetPrivateKey
- * @key randomness
*/
import java.util.*;
@@ -49,18 +49,17 @@
System.out.println(p);
Security.addProvider(p);
- KeyStore ks = KeyStore.getInstance("PKCS11", p);
+ KeyStore ks = KeyStore.getInstance(PKCS11, p);
ks.load(null, password);
- Collection<String> aliases = new TreeSet<String>(Collections.list(ks.aliases()));
+ Collection<String> aliases = new TreeSet<>(
+ Collections.list(ks.aliases()));
System.out.println("entries: " + aliases.size());
System.out.println(aliases);
PrivateKey privateKey = (PrivateKey)ks.getKey(keyAlias, password);
System.out.println(privateKey);
- byte[] data = new byte[1024];
- Random random = new Random();
- random.nextBytes(data);
+ byte[] data = generateData(1024);
System.out.println("Signing...");
Signature signature = Signature.getInstance("MD5withRSA");
@@ -68,7 +67,8 @@
signature.update(data);
byte[] sig = signature.sign();
- X509Certificate[] chain = (X509Certificate[])ks.getCertificateChain(keyAlias);
+ X509Certificate[] chain =
+ (X509Certificate[]) ks.getCertificateChain(keyAlias);
signature.initVerify(chain[0].getPublicKey());
signature.update(data);
boolean ok = signature.verify(sig);