src/java.base/share/classes/sun/security/rsa/RSAPublicKeyImpl.java
author valeriep
Mon, 21 May 2018 23:40:52 +0000
changeset 50204 3195a713e24d
parent 48567 c4de888db380
child 50918 ebff24bd9302
permissions -rw-r--r--
8146293: Add support for RSASSA-PSS Signature algorithm Summary: add RSASSA-PSS key and signature support to SunRsaSign provider Reviewed-by: wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2596
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2596
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2596
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2596
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2596
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.rsa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.*;
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    32
import java.security.spec.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.interfaces.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.x509.X509Key;
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    37
import sun.security.x509.AlgorithmId;
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    38
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    39
import static sun.security.rsa.RSAUtil.KeyType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    42
 * RSA public key implementation for "RSA", "RSASSA-PSS" algorithms.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Note: RSA keys must be at least 512 bits long
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @see RSAPrivateCrtKeyImpl
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    47
 * @see RSAPrivateKeyImpl
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @see RSAKeyFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public final class RSAPublicKeyImpl extends X509Key implements RSAPublicKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static final long serialVersionUID = 2644735423591199609L;
48567
c4de888db380 8174756: Extra validation for public keys
apetcher
parents: 47216
diff changeset
    56
    private static final BigInteger THREE = BigInteger.valueOf(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private BigInteger n;       // modulus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private BigInteger e;       // public exponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    61
    // optional parameters associated with this RSA key
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    62
    // specified in the encoding of its AlgorithmId
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    63
    // must be null for "RSA" keys.
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    64
    private AlgorithmParameterSpec keyParams;
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    65
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    67
     * Generate a new RSAPublicKey from the specified encoding.
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    68
     * Used by SunPKCS11 provider.
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    69
     */
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    70
    public static RSAPublicKey newKey(byte[] encoded)
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    71
            throws InvalidKeyException {
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    72
        return new RSAPublicKeyImpl(encoded);
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    73
    }
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    74
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    75
    /**
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    76
     * Generate a new RSAPublicKey from the specified type and components.
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    77
     * Used by SunPKCS11 provider.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    79
    public static RSAPublicKey newKey(KeyType type,
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    80
            AlgorithmParameterSpec params, BigInteger n, BigInteger e)
2596
a1964c157e68 6497740: Limit the size of RSA public keys
wetmore
parents: 2
diff changeset
    81
            throws InvalidKeyException {
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    82
        AlgorithmId rsaId = RSAUtil.createAlgorithmId(type, params);
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    83
        return new RSAPublicKeyImpl(rsaId, n, e);
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    84
    }
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    85
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    86
    /**
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    87
     * Construct a RSA key from AlgorithmId and its components. Used by
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    88
     * RSAKeyFactory and RSAKeyPairGenerator.
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    89
     */
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    90
    RSAPublicKeyImpl(AlgorithmId rsaId, BigInteger n, BigInteger e)
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    91
            throws InvalidKeyException {
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    92
        RSAKeyFactory.checkRSAProviderKeyLengths(n.bitLength(), e);
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    93
        checkExponentRange(n, e);
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    94
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        this.n = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        this.e = e;
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    97
        this.keyParams = RSAUtil.getParamSpec(rsaId);
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
    98
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        // generate the encoding
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   100
        algid = rsaId;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            out.putInteger(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            out.putInteger(e);
19375
cdfdb9c0590e 8022461: Fix lint warnings in sun.security.{provider,rsa,x509}
juh
parents: 5506
diff changeset
   105
            byte[] keyArray =
cdfdb9c0590e 8022461: Fix lint warnings in sun.security.{provider,rsa,x509}
juh
parents: 5506
diff changeset
   106
                new DerValue(DerValue.tag_Sequence,
cdfdb9c0590e 8022461: Fix lint warnings in sun.security.{provider,rsa,x509}
juh
parents: 5506
diff changeset
   107
                             out.toByteArray()).toByteArray();
cdfdb9c0590e 8022461: Fix lint warnings in sun.security.{provider,rsa,x509}
juh
parents: 5506
diff changeset
   108
            setKey(new BitArray(keyArray.length*8, keyArray));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        } catch (IOException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            // should never occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            throw new InvalidKeyException(exc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Construct a key from its encoding. Used by RSAKeyFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   118
    RSAPublicKeyImpl(byte[] encoded) throws InvalidKeyException {
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   119
        decode(encoded); // this sets n and e value
2596
a1964c157e68 6497740: Limit the size of RSA public keys
wetmore
parents: 2
diff changeset
   120
        RSAKeyFactory.checkRSAProviderKeyLengths(n.bitLength(), e);
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   121
        checkExponentRange(n, e);
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   122
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   123
        try {
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   124
            // this will check the validity of params
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   125
            this.keyParams = RSAUtil.getParamSpec(algid);
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   126
        } catch (ProviderException e) {
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   127
            throw new InvalidKeyException(e);
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   128
        }
48567
c4de888db380 8174756: Extra validation for public keys
apetcher
parents: 47216
diff changeset
   129
    }
c4de888db380 8174756: Extra validation for public keys
apetcher
parents: 47216
diff changeset
   130
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   131
    // pkg private utility method for checking RSA modulus and public exponent
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   132
    static void checkExponentRange(BigInteger mod, BigInteger exp)
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   133
            throws InvalidKeyException {
48567
c4de888db380 8174756: Extra validation for public keys
apetcher
parents: 47216
diff changeset
   134
        // the exponent should be smaller than the modulus
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   135
        if (exp.compareTo(mod) >= 0) {
48567
c4de888db380 8174756: Extra validation for public keys
apetcher
parents: 47216
diff changeset
   136
            throw new InvalidKeyException("exponent is larger than modulus");
c4de888db380 8174756: Extra validation for public keys
apetcher
parents: 47216
diff changeset
   137
        }
c4de888db380 8174756: Extra validation for public keys
apetcher
parents: 47216
diff changeset
   138
c4de888db380 8174756: Extra validation for public keys
apetcher
parents: 47216
diff changeset
   139
        // the exponent should be at least 3
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   140
        if (exp.compareTo(THREE) < 0) {
48567
c4de888db380 8174756: Extra validation for public keys
apetcher
parents: 47216
diff changeset
   141
            throw new InvalidKeyException("exponent is smaller than 3");
c4de888db380 8174756: Extra validation for public keys
apetcher
parents: 47216
diff changeset
   142
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    // see JCA doc
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   146
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public String getAlgorithm() {
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   148
        return algid.getName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    // see JCA doc
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   152
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public BigInteger getModulus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    // see JCA doc
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   158
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public BigInteger getPublicExponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   163
    // see JCA doc
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   164
    @Override
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   165
    public AlgorithmParameterSpec getParams() {
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   166
        return keyParams;
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   167
    }
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   168
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Parse the key. Called by X509Key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    protected void parseKeyBits() throws InvalidKeyException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        try {
19375
cdfdb9c0590e 8022461: Fix lint warnings in sun.security.{provider,rsa,x509}
juh
parents: 5506
diff changeset
   174
            DerInputStream in = new DerInputStream(getKey().toByteArray());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            DerValue derValue = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            if (derValue.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                throw new IOException("Not a SEQUENCE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            DerInputStream data = derValue.data;
44260
dd947f766e11 8175251: Failed to load RSA private key from pkcs12
valeriep
parents: 25859
diff changeset
   180
            n = data.getPositiveBigInteger();
dd947f766e11 8175251: Failed to load RSA private key from pkcs12
valeriep
parents: 25859
diff changeset
   181
            e = data.getPositiveBigInteger();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            if (derValue.data.available() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                throw new IOException("Extra data available");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            throw new InvalidKeyException("Invalid RSA public key", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    // return a string representation of this key for debugging
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   191
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public String toString() {
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   193
        return "Sun " + getAlgorithm() + " public key, " + n.bitLength()
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   194
               + " bits" + "\n  params: " + keyParams + "\n  modulus: " + n
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 48567
diff changeset
   195
               + "\n  public exponent: " + e;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    protected Object writeReplace() throws java.io.ObjectStreamException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return new KeyRep(KeyRep.Type.PUBLIC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                        getAlgorithm(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        getFormat(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                        getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
}