Path: blob/master/test/jdk/sun/security/mscapi/IsSunMSCAPIAvailable.java
41149 views
/*1* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 6318171 693156226* @requires os.family == "windows"27* @modules jdk.crypto.mscapi/sun.security.mscapi28* @run main/othervm IsSunMSCAPIAvailable29*/3031import java.security.Provider;32import java.security.*;33import javax.crypto.Cipher;3435public class IsSunMSCAPIAvailable {3637public static void main(String[] args) throws Exception {3839// Dynamically register the SunMSCAPI provider40Security.addProvider(new sun.security.mscapi.SunMSCAPI());414243Provider p = Security.getProvider("SunMSCAPI");4445System.out.println("SunMSCAPI provider classname is " +46p.getClass().getName());47System.out.println("SunMSCAPI provider name is " + p.getName());48System.out.println("SunMSCAPI provider version # is " + p.getVersion());49System.out.println("SunMSCAPI provider info is " + p.getInfo());5051/*52* Secure Random53*/54SecureRandom random = SecureRandom.getInstance("Windows-PRNG", p);55System.out.println(" Windows-PRNG is implemented by: " +56random.getClass().getName());5758/*59* Key Store60*/61KeyStore keystore = KeyStore.getInstance("Windows-MY", p);62System.out.println(" Windows-MY is implemented by: " +63keystore.getClass().getName());6465keystore = KeyStore.getInstance("Windows-ROOT", p);66System.out.println(" Windows-ROOT is implemented by: " +67keystore.getClass().getName());6869/*70* Signature71*/72Signature signature = Signature.getInstance("SHA1withRSA", p);73System.out.println(" SHA1withRSA is implemented by: " +74signature.getClass().getName());7576signature = Signature.getInstance("MD5withRSA", p);77System.out.println(" MD5withRSA is implemented by: " +78signature.getClass().getName());7980signature = Signature.getInstance("MD2withRSA", p);81System.out.println(" MD2withRSA is implemented by: " +82signature.getClass().getName());8384/*85* Key Pair Generator86*/87KeyPairGenerator keypairGenerator =88KeyPairGenerator.getInstance("RSA", p);89System.out.println(" RSA is implemented by: " +90keypairGenerator.getClass().getName());9192/*93* Cipher94*/95Cipher cipher = null;9697try {98cipher = Cipher.getInstance("RSA", p);99System.out.println(" RSA is implemented by: " +100cipher.getClass().getName());101102cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", p);103System.out.println(" RSA/ECB/PKCS1Padding is implemented by: " +104cipher.getClass().getName());105106} catch (GeneralSecurityException e) {107System.out.println("Cipher not supported by provider, skipping...");108}109}110}111112113