1 /*
   2  * Copyright (c) 2005, 2017, 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  * @run main/othervm IsSunMSCAPIAvailable
  30  */
  31 
  32 import java.security.Provider;
  33 import java.security.*;
  34 import javax.crypto.Cipher;
  35 
  36 public class IsSunMSCAPIAvailable {
  37 
  38     public static void main(String[] args) throws Exception {
  39 
  40         // Dynamically register the SunMSCAPI provider
  41         Security.addProvider(new sun.security.mscapi.SunMSCAPI());
  42 
  43 
  44         Provider p = Security.getProvider("SunMSCAPI");
  45 
  46         System.out.println("SunMSCAPI provider classname is " +
  47             p.getClass().getName());
  48         System.out.println("SunMSCAPI provider name is " + p.getName());
  49         System.out.println("SunMSCAPI provider version # is " + p.getVersion());
  50         System.out.println("SunMSCAPI provider info is " + p.getInfo());
  51 
  52         /*
  53          * Secure Random
  54          */
  55         SecureRandom random = SecureRandom.getInstance("Windows-PRNG", p);
  56         System.out.println("    Windows-PRNG is implemented by: " +
  57             random.getClass().getName());
  58 
  59         /*
  60          * Key Store
  61          */
  62         KeyStore keystore = KeyStore.getInstance("Windows-MY", p);
  63         System.out.println("    Windows-MY is implemented by: " +
  64             keystore.getClass().getName());
  65 
  66         keystore = KeyStore.getInstance("Windows-ROOT", p);
  67         System.out.println("    Windows-ROOT is implemented by: " +
  68             keystore.getClass().getName());
  69 
  70         /*
  71          * Signature
  72          */
  73         Signature signature = Signature.getInstance("SHA1withRSA", p);
  74         System.out.println("    SHA1withRSA is implemented by: " +
  75             signature.getClass().getName());
  76 
  77         signature = Signature.getInstance("MD5withRSA", p);
  78         System.out.println("    MD5withRSA is implemented by: " +
  79             signature.getClass().getName());
  80 
  81         signature = Signature.getInstance("MD2withRSA", p);
  82         System.out.println("    MD2withRSA is implemented by: " +
  83             signature.getClass().getName());
  84 
  85         /*
  86          * Key Pair Generator
  87          */
  88         KeyPairGenerator keypairGenerator =
  89             KeyPairGenerator.getInstance("RSA", p);
  90         System.out.println("    RSA is implemented by: " +
  91             keypairGenerator.getClass().getName());
  92 
  93         /*
  94          * Cipher
  95          */
  96         Cipher cipher = null;
  97 
  98         try {
  99             cipher = Cipher.getInstance("RSA", p);
 100             System.out.println("    RSA is implemented by: " +
 101                 cipher.getClass().getName());
 102 
 103             cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", p);
 104             System.out.println("    RSA/ECB/PKCS1Padding is implemented by: " +
 105                 cipher.getClass().getName());
 106 
 107         } catch (GeneralSecurityException e) {
 108             System.out.println("Cipher not supported by provider, skipping...");
 109         }
 110     }
 111 }