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