jdk/test/sun/security/mscapi/SignUsingSHA2withRSA.java
author vinnie
Fri, 29 Apr 2011 00:21:54 +0100
changeset 9533 13cc5e8eb9f1
parent 9524 8417d0e74ac5
child 12685 8a448b5b9006
permissions -rw-r--r--
6578658: Request for raw RSA (NONEwithRSA) Signature support in SunMSCAPI Reviewed-by: wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9524
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
     1
/*
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
     4
 *
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
     8
 *
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    13
 * accompanied this code).
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    14
 *
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    18
 *
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    21
 * questions.
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    22
 */
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    23
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    24
/**
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    25
 * @see SignUsingSHA2withRSA.sh
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    26
 */
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    27
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    28
import java.security.*;
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    29
import java.util.*;
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    30
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    31
public class SignUsingSHA2withRSA {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    32
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    33
    private static final byte[] toBeSigned = new byte[] {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    34
        0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    35
    };
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    36
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    37
    private static List<byte[]> generatedSignatures = new ArrayList<>();
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    38
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    40
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    41
        Provider[] providers = Security.getProviders("Signature.SHA256withRSA");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    42
        if (providers == null) {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    43
            System.out.println("No JCE providers support the " +
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    44
                "'Signature.SHA256withRSA' algorithm");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    45
            System.out.println("Skipping this test...");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    46
            return;
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    47
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    48
        } else {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    49
            System.out.println("The following JCE providers support the " +
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    50
                "'Signature.SHA256withRSA' algorithm: ");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    51
            for (Provider provider : providers) {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    52
                System.out.println("    " + provider.getName());
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    53
            }
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    54
        }
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    55
        System.out.println("-------------------------------------------------");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    56
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    57
        KeyStore ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    58
        ks.load(null, null);
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    59
        System.out.println("Loaded keystore: Windows-MY");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    60
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    61
        Enumeration e = ks.aliases();
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    62
        PrivateKey privateKey = null;
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    63
        PublicKey publicKey = null;
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    64
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    65
        while (e.hasMoreElements()) {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    66
            String alias = (String) e.nextElement();
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    67
            if (alias.equals("6753664")) {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    68
                System.out.println("Loaded entry: " + alias);
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    69
                privateKey = (PrivateKey) ks.getKey(alias, null);
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    70
                publicKey = (PublicKey) ks.getCertificate(alias).getPublicKey();
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    71
            }
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    72
        }
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    73
        if (privateKey == null || publicKey == null) {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    74
            throw new Exception("Cannot load the keys need to run this test");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    75
        }
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    76
        System.out.println("-------------------------------------------------");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    77
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    78
        generatedSignatures.add(signUsing("SHA256withRSA", privateKey));
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    79
        generatedSignatures.add(signUsing("SHA384withRSA", privateKey));
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    80
        generatedSignatures.add(signUsing("SHA512withRSA", privateKey));
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    81
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    82
        System.out.println("-------------------------------------------------");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    83
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    84
        verifyUsing("SHA256withRSA", publicKey, generatedSignatures.get(0));
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    85
        verifyUsing("SHA384withRSA", publicKey, generatedSignatures.get(1));
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    86
        verifyUsing("SHA512withRSA", publicKey, generatedSignatures.get(2));
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    87
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    88
        System.out.println("-------------------------------------------------");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    89
    }
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    90
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    91
    private static byte[] signUsing(String signAlgorithm,
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    92
        PrivateKey privateKey) throws Exception {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    93
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    94
        // Must explicitly specify the SunMSCAPI JCE provider
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    95
        // (otherwise SunJCE is chosen because it appears earlier in the list)
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    96
        Signature sig1 = Signature.getInstance(signAlgorithm, "SunMSCAPI");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    97
        if (sig1 == null) {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    98
            throw new Exception("'" + signAlgorithm + "' is not supported");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
    99
        }
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   100
        System.out.println("Using " + signAlgorithm + " signer from the " +
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   101
            sig1.getProvider().getName() + " JCE provider");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   102
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   103
        System.out.println("Using key: " + privateKey);
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   104
        sig1.initSign(privateKey);
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   105
        sig1.update(toBeSigned);
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   106
        byte [] sigBytes = null;
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   107
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   108
        try {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   109
            sigBytes = sig1.sign();
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   110
            System.out.println("Generated RSA signature over a " +
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   111
                toBeSigned.length + "-byte data (signature length: " +
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   112
                sigBytes.length * 8 + " bits)");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   113
            System.out.println(String.format("0x%0" +
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   114
                (sigBytes.length * 2) + "x",
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   115
                new java.math.BigInteger(1, sigBytes)));
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   116
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   117
        } catch (SignatureException se) {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   118
                System.out.println("Error generating RSA signature: " + se);
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   119
        }
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   120
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   121
        return sigBytes;
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   122
    }
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   123
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   124
    private static void verifyUsing(String signAlgorithm, PublicKey publicKey,
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   125
        byte[] signature) throws Exception {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   126
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   127
        // Must explicitly specify the SunMSCAPI JCE provider
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   128
        // (otherwise SunJCE is chosen because it appears earlier in the list)
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   129
        Signature sig1 = Signature.getInstance(signAlgorithm, "SunMSCAPI");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   130
        if (sig1 == null) {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   131
            throw new Exception("'" + signAlgorithm + "' is not supported");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   132
        }
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   133
        System.out.println("Using " + signAlgorithm + " verifier from the "
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   134
            + sig1.getProvider().getName() + " JCE provider");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   135
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   136
        System.out.println("Using key: " + publicKey);
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   137
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   138
        System.out.println("\nVerifying RSA Signature over a " +
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   139
            toBeSigned.length + "-byte data (signature length: " +
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   140
            signature.length * 8 + " bits)");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   141
        System.out.println(String.format("0x%0" + (signature.length * 2) +
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   142
            "x", new java.math.BigInteger(1, signature)));
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   143
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   144
        sig1.initVerify(publicKey);
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   145
        sig1.update(toBeSigned);
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   146
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   147
        if (sig1.verify(signature)) {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   148
            System.out.println("Verify PASSED\n");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   149
        } else {
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   150
            throw new Exception("Verify FAILED");
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   151
        }
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   152
    }
8417d0e74ac5 6753664: Support SHA256 (and higher) in SunMSCAPI
vinnie
parents:
diff changeset
   153
}