src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CPublicKey.java
changeset 54639 2cac7d48db4c
parent 53007 e2798bf6318a
child 54827 01fa7f06f806
equal deleted inserted replaced
54638:9b8926bf85c1 54639:2cac7d48db4c
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    57     public static class CECPublicKey extends CPublicKey implements ECPublicKey {
    57     public static class CECPublicKey extends CPublicKey implements ECPublicKey {
    58 
    58 
    59         private ECPoint w = null;
    59         private ECPoint w = null;
    60         private static final long serialVersionUID = 12L;
    60         private static final long serialVersionUID = 12L;
    61 
    61 
    62         CECPublicKey(long hCryptProv, int keyLength) {
    62         CECPublicKey(NativeHandles handles, int keyLength) {
    63             super("EC", hCryptProv, 0, keyLength);
    63             super("EC", handles, keyLength);
    64         }
    64         }
    65 
    65 
    66         @Override
    66         @Override
    67         public ECPoint getW() {
    67         public ECPoint getW() {
    68             if (w == null) {
    68             if (w == null) {
   119 
   119 
   120         private BigInteger modulus = null;
   120         private BigInteger modulus = null;
   121         private BigInteger exponent = null;
   121         private BigInteger exponent = null;
   122         private static final long serialVersionUID = 12L;
   122         private static final long serialVersionUID = 12L;
   123 
   123 
   124         CRSAPublicKey(long hCryptProv, long hCryptKey, int keyLength) {
   124         CRSAPublicKey(NativeHandles handles, int keyLength) {
   125             super("RSA", hCryptProv, hCryptKey, keyLength);
   125             super("RSA", handles, keyLength);
   126         }
   126         }
   127 
   127 
   128         public String toString() {
   128         public String toString() {
   129             StringBuffer sb = new StringBuffer();
   129             StringBuffer sb = new StringBuffer();
   130             sb.append(algorithm + "PublicKey [size=").append(keyLength)
   130             sb.append(algorithm + "PublicKey [size=").append(keyLength)
   179         private native byte[] getExponent(byte[] keyBlob) throws KeyException;
   179         private native byte[] getExponent(byte[] keyBlob) throws KeyException;
   180 
   180 
   181         private native byte[] getModulus(byte[] keyBlob) throws KeyException;
   181         private native byte[] getModulus(byte[] keyBlob) throws KeyException;
   182     }
   182     }
   183 
   183 
       
   184     // Called by native code inside security.cpp
       
   185     static CPublicKey of(
       
   186             String alg, long hCryptProv, long hCryptKey, int keyLength) {
       
   187         return of(alg, new NativeHandles(hCryptProv, hCryptKey), keyLength);
       
   188     }
       
   189 
   184     public static CPublicKey of(
   190     public static CPublicKey of(
   185             String alg, long hCryptProv, long hCryptKey, int keyLength) {
   191             String alg, NativeHandles handles, int keyLength) {
   186         switch (alg) {
   192         switch (alg) {
   187             case "RSA":
   193             case "RSA":
   188                 return new CRSAPublicKey(hCryptProv, hCryptKey, keyLength);
   194                 return new CRSAPublicKey(handles, keyLength);
   189             case "EC":
   195             case "EC":
   190                 return new CECPublicKey(hCryptProv, keyLength);
   196                 return new CECPublicKey(handles, keyLength);
   191             default:
   197             default:
   192                 throw new AssertionError("Unsupported algorithm: " + alg);
   198                 throw new AssertionError("Unsupported algorithm: " + alg);
   193         }
   199         }
   194     }
   200     }
   195 
   201 
   196     protected CPublicKey(
   202     protected CPublicKey(
   197             String alg, long hCryptProv, long hCryptKey, int keyLength) {
   203             String alg, NativeHandles handles, int keyLength) {
   198         super(alg, hCryptProv, hCryptKey, keyLength);
   204         super(alg, handles, keyLength);
   199     }
   205     }
   200 
   206 
   201     @Override
   207     @Override
   202     public String getFormat() {
   208     public String getFormat() {
   203         return "X.509";
   209         return "X.509";