1 /* 2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 6318171 6931562 27 * @requires os.family == "windows" 28 * @modules jdk.crypto.mscapi/sun.security.mscapi 29 * @compile --add-modules jdk.crypto.mscapi IsSunMSCAPIAvailable.java 30 * @run main/othervm IsSunMSCAPIAvailable 31 */ 32 33 import java.security.Provider; 34 import java.security.*; 35 import javax.crypto.Cipher; 36 37 public class IsSunMSCAPIAvailable { 38 39 public static void main(String[] args) throws Exception { 40 41 // Dynamically register the SunMSCAPI provider 42 Security.addProvider(new sun.security.mscapi.SunMSCAPI()); 43 44 45 Provider p = Security.getProvider("SunMSCAPI"); 46 47 System.out.println("SunMSCAPI provider classname is " + 48 p.getClass().getName()); 49 System.out.println("SunMSCAPI provider name is " + p.getName()); 50 System.out.println("SunMSCAPI provider version # is " + p.getVersion()); 51 System.out.println("SunMSCAPI provider info is " + p.getInfo()); 52 53 /* 54 * Secure Random 55 */ 56 SecureRandom random = SecureRandom.getInstance("Windows-PRNG", p); 57 System.out.println(" Windows-PRNG is implemented by: " + 58 random.getClass().getName()); 59 60 /* 61 * Key Store 62 */ 63 KeyStore keystore = KeyStore.getInstance("Windows-MY", p); 64 System.out.println(" Windows-MY is implemented by: " + 65 keystore.getClass().getName()); 66 67 keystore = KeyStore.getInstance("Windows-ROOT", p); 68 System.out.println(" Windows-ROOT is implemented by: " + 69 keystore.getClass().getName()); 70 71 /* 72 * Signature 73 */ 74 Signature signature = Signature.getInstance("SHA1withRSA", p); 75 System.out.println(" SHA1withRSA is implemented by: " + 76 signature.getClass().getName()); 77 78 signature = Signature.getInstance("MD5withRSA", p); 79 System.out.println(" MD5withRSA is implemented by: " + 80 signature.getClass().getName()); 81 82 signature = Signature.getInstance("MD2withRSA", p); 83 System.out.println(" MD2withRSA is implemented by: " + 84 signature.getClass().getName()); 85 86 /* 87 * Key Pair Generator 88 */ 89 KeyPairGenerator keypairGenerator = 90 KeyPairGenerator.getInstance("RSA", p); 91 System.out.println(" RSA is implemented by: " + 92 keypairGenerator.getClass().getName()); 93 94 /* 95 * Cipher 96 */ 97 Cipher cipher = null; 98 99 try { 100 cipher = Cipher.getInstance("RSA", p); 101 System.out.println(" RSA is implemented by: " + 102 cipher.getClass().getName()); 103 104 cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", p); 105 System.out.println(" RSA/ECB/PKCS1Padding is implemented by: " + 106 cipher.getClass().getName()); 107 108 } catch (GeneralSecurityException e) { 109 System.out.println("Cipher not supported by provider, skipping..."); 110 } 111 } 112 }