< prev index next >

src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/RSAPublicKey.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2016, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.mscapi;
  27 
  28 import java.math.BigInteger;
  29 import java.security.KeyException;
  30 import java.security.KeyRep;
  31 import java.security.ProviderException;
  32 

  33 import sun.security.rsa.RSAPublicKeyImpl;
  34 
  35 /**
  36  * The handle for an RSA public key using the Microsoft Crypto API.
  37  *
  38  * @since 1.6
  39  */
  40 class RSAPublicKey extends Key implements java.security.interfaces.RSAPublicKey
  41 {
  42     private static final long serialVersionUID = -2289561342425825391L;
  43 
  44     private byte[] publicKeyBlob = null;
  45     private byte[] encoding = null;
  46     private BigInteger modulus = null;
  47     private BigInteger exponent = null;
  48 
  49     /**
  50      * Construct an RSAPublicKey object.
  51      */
  52     RSAPublicKey(long hCryptProv, long hCryptKey, int keyLength)


 148      *
 149      * @return the primary encoding format of the key.
 150      */
 151     public String getFormat()
 152     {
 153         return "X.509";
 154     }
 155 
 156     /**
 157      * Returns the key in its primary encoding format, or null
 158      * if this key does not support encoding.
 159      *
 160      * @return the encoded key, or null if the key does not support
 161      * encoding.
 162      */
 163     public byte[] getEncoded()
 164     {
 165         if (encoding == null) {
 166 
 167             try {
 168                 encoding = new RSAPublicKeyImpl(getModulus(),
 169                     getPublicExponent()).getEncoded();
 170 
 171             } catch (KeyException e) {
 172                 // ignore
 173             }
 174         }
 175         return encoding;
 176     }
 177 
 178     protected Object writeReplace() throws java.io.ObjectStreamException {
 179         return new KeyRep(KeyRep.Type.PUBLIC,
 180                         getAlgorithm(),
 181                         getFormat(),
 182                         getEncoded());
 183     }
 184 
 185     /*
 186      * Returns the Microsoft CryptoAPI representation of the key.
 187      */
 188     private native byte[] getPublicKeyBlob(long hCryptKey) throws KeyException;
 189 
   1 /*
   2  * Copyright (c) 2005, 2018, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.mscapi;
  27 
  28 import java.math.BigInteger;
  29 import java.security.KeyException;
  30 import java.security.KeyRep;
  31 import java.security.ProviderException;
  32 
  33 import sun.security.rsa.RSAUtil.KeyType;
  34 import sun.security.rsa.RSAPublicKeyImpl;
  35 
  36 /**
  37  * The handle for an RSA public key using the Microsoft Crypto API.
  38  *
  39  * @since 1.6
  40  */
  41 class RSAPublicKey extends Key implements java.security.interfaces.RSAPublicKey
  42 {
  43     private static final long serialVersionUID = -2289561342425825391L;
  44 
  45     private byte[] publicKeyBlob = null;
  46     private byte[] encoding = null;
  47     private BigInteger modulus = null;
  48     private BigInteger exponent = null;
  49 
  50     /**
  51      * Construct an RSAPublicKey object.
  52      */
  53     RSAPublicKey(long hCryptProv, long hCryptKey, int keyLength)


 149      *
 150      * @return the primary encoding format of the key.
 151      */
 152     public String getFormat()
 153     {
 154         return "X.509";
 155     }
 156 
 157     /**
 158      * Returns the key in its primary encoding format, or null
 159      * if this key does not support encoding.
 160      *
 161      * @return the encoded key, or null if the key does not support
 162      * encoding.
 163      */
 164     public byte[] getEncoded()
 165     {
 166         if (encoding == null) {
 167 
 168             try {
 169                 encoding = RSAPublicKeyImpl.newKey(KeyType.RSA, null,
 170                     getModulus(), getPublicExponent()).getEncoded();
 171 
 172             } catch (KeyException e) {
 173                 // ignore
 174             }
 175         }
 176         return encoding;
 177     }
 178 
 179     protected Object writeReplace() throws java.io.ObjectStreamException {
 180         return new KeyRep(KeyRep.Type.PUBLIC,
 181                         getAlgorithm(),
 182                         getFormat(),
 183                         getEncoded());
 184     }
 185 
 186     /*
 187      * Returns the Microsoft CryptoAPI representation of the key.
 188      */
 189     private native byte[] getPublicKeyBlob(long hCryptKey) throws KeyException;
 190 
< prev index next >