Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/mscapi/IsSunMSCAPIAvailable.java
38840 views
/*1* Copyright (c) 2005, 2015, 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* @see IsSunMSCAPIAvailable.sh25*/2627import java.security.Provider;28import java.security.*;29import javax.crypto.Cipher;3031public class IsSunMSCAPIAvailable {3233public static void main(String[] args) throws Exception {3435// Dynamically register the SunMSCAPI provider36Security.addProvider(new sun.security.mscapi.SunMSCAPI());373839Provider p = Security.getProvider("SunMSCAPI");4041System.out.println("SunMSCAPI provider classname is " +42p.getClass().getName());43System.out.println("SunMSCAPI provider name is " + p.getName());44System.out.println("SunMSCAPI provider version # is " + p.getVersion());45System.out.println("SunMSCAPI provider info is " + p.getInfo());4647/*48* Secure Random49*/50SecureRandom random = SecureRandom.getInstance("Windows-PRNG", p);51System.out.println(" Windows-PRNG is implemented by: " +52random.getClass().getName());5354/*55* Key Store56*/57KeyStore keystore = KeyStore.getInstance("Windows-MY", p);58System.out.println(" Windows-MY is implemented by: " +59keystore.getClass().getName());6061keystore = KeyStore.getInstance("Windows-ROOT", p);62System.out.println(" Windows-ROOT is implemented by: " +63keystore.getClass().getName());6465/*66* Signature67*/68Signature signature = Signature.getInstance("SHA1withRSA", p);69System.out.println(" SHA1withRSA is implemented by: " +70signature.getClass().getName());7172signature = Signature.getInstance("MD5withRSA", p);73System.out.println(" MD5withRSA is implemented by: " +74signature.getClass().getName());7576signature = Signature.getInstance("MD2withRSA", p);77System.out.println(" MD2withRSA is implemented by: " +78signature.getClass().getName());7980/*81* Key Pair Generator82*/83KeyPairGenerator keypairGenerator =84KeyPairGenerator.getInstance("RSA", p);85System.out.println(" RSA is implemented by: " +86keypairGenerator.getClass().getName());8788/*89* Cipher90*/91Cipher cipher = null;9293try {94cipher = Cipher.getInstance("RSA", p);95System.out.println(" RSA is implemented by: " +96cipher.getClass().getName());9798cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", p);99System.out.println(" RSA/ECB/PKCS1Padding is implemented by: " +100cipher.getClass().getName());101102} catch (GeneralSecurityException e) {103System.out.println("Cipher not supported by provider, skipping...");104}105}106}107108109