< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2005, 2012, 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


 142 
 143     // no iv, return null
 144     // see JCE spec
 145     protected byte[] engineGetIV() {
 146         return null;
 147     }
 148 
 149     // no parameters, return null
 150     // see JCE spec
 151     protected AlgorithmParameters engineGetParameters() {
 152         return null;
 153     }
 154 
 155     // see JCE spec
 156     protected void engineInit(int opmode, Key key, SecureRandom random)
 157             throws InvalidKeyException {
 158         init(opmode, key);
 159     }
 160 
 161     // see JCE spec

 162     protected void engineInit(int opmode, Key key,
 163             AlgorithmParameterSpec params, SecureRandom random)
 164             throws InvalidKeyException, InvalidAlgorithmParameterException {
 165 
 166         if (params != null) {
 167             if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
 168                 throw new InvalidAlgorithmParameterException(
 169                         "Parameters not supported");
 170             }
 171             spec = params;
 172             this.random = random;   // for TLS RSA premaster secret
 173         }
 174         init(opmode, key);
 175     }
 176 
 177     // see JCE spec
 178     protected void engineInit(int opmode, Key key,
 179             AlgorithmParameters params, SecureRandom random)
 180             throws InvalidKeyException, InvalidAlgorithmParameterException {
 181 


 352     // see JCE spec
 353     protected byte[] engineWrap(Key key) throws InvalidKeyException,
 354             IllegalBlockSizeException {
 355         byte[] encoded = key.getEncoded(); // TODO - unextractable key
 356         if ((encoded == null) || (encoded.length == 0)) {
 357             throw new InvalidKeyException("Could not obtain encoded key");
 358         }
 359         if (encoded.length > buffer.length) {
 360             throw new InvalidKeyException("Key is too long for wrapping");
 361         }
 362         update(encoded, 0, encoded.length);
 363         try {
 364             return doFinal();
 365         } catch (BadPaddingException e) {
 366             // should not occur
 367             throw new InvalidKeyException("Wrapping failed", e);
 368         }
 369     }
 370 
 371     // see JCE spec

 372     protected java.security.Key engineUnwrap(byte[] wrappedKey,
 373             String algorithm,
 374             int type) throws InvalidKeyException, NoSuchAlgorithmException {
 375 
 376         if (wrappedKey.length > buffer.length) {
 377             throw new InvalidKeyException("Key is too long for unwrapping");
 378         }
 379 
 380         boolean isTlsRsaPremasterSecret =
 381                 algorithm.equals("TlsRsaPremasterSecret");
 382         Exception failover = null;
 383         byte[] encoded = null;
 384 
 385         update(wrappedKey, 0, wrappedKey.length);
 386         try {
 387             encoded = doFinal();
 388         } catch (BadPaddingException e) {
 389             if (isTlsRsaPremasterSecret) {
 390                 failover = e;
 391             } else {


   1 /*
   2  * Copyright (c) 2005, 2014, 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


 142 
 143     // no iv, return null
 144     // see JCE spec
 145     protected byte[] engineGetIV() {
 146         return null;
 147     }
 148 
 149     // no parameters, return null
 150     // see JCE spec
 151     protected AlgorithmParameters engineGetParameters() {
 152         return null;
 153     }
 154 
 155     // see JCE spec
 156     protected void engineInit(int opmode, Key key, SecureRandom random)
 157             throws InvalidKeyException {
 158         init(opmode, key);
 159     }
 160 
 161     // see JCE spec
 162     @SuppressWarnings("deprecation")
 163     protected void engineInit(int opmode, Key key,
 164             AlgorithmParameterSpec params, SecureRandom random)
 165             throws InvalidKeyException, InvalidAlgorithmParameterException {
 166 
 167         if (params != null) {
 168             if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
 169                 throw new InvalidAlgorithmParameterException(
 170                         "Parameters not supported");
 171             }
 172             spec = params;
 173             this.random = random;   // for TLS RSA premaster secret
 174         }
 175         init(opmode, key);
 176     }
 177 
 178     // see JCE spec
 179     protected void engineInit(int opmode, Key key,
 180             AlgorithmParameters params, SecureRandom random)
 181             throws InvalidKeyException, InvalidAlgorithmParameterException {
 182 


 353     // see JCE spec
 354     protected byte[] engineWrap(Key key) throws InvalidKeyException,
 355             IllegalBlockSizeException {
 356         byte[] encoded = key.getEncoded(); // TODO - unextractable key
 357         if ((encoded == null) || (encoded.length == 0)) {
 358             throw new InvalidKeyException("Could not obtain encoded key");
 359         }
 360         if (encoded.length > buffer.length) {
 361             throw new InvalidKeyException("Key is too long for wrapping");
 362         }
 363         update(encoded, 0, encoded.length);
 364         try {
 365             return doFinal();
 366         } catch (BadPaddingException e) {
 367             // should not occur
 368             throw new InvalidKeyException("Wrapping failed", e);
 369         }
 370     }
 371 
 372     // see JCE spec
 373     @SuppressWarnings("deprecation")
 374     protected java.security.Key engineUnwrap(byte[] wrappedKey,
 375             String algorithm,
 376             int type) throws InvalidKeyException, NoSuchAlgorithmException {
 377 
 378         if (wrappedKey.length > buffer.length) {
 379             throw new InvalidKeyException("Key is too long for unwrapping");
 380         }
 381 
 382         boolean isTlsRsaPremasterSecret =
 383                 algorithm.equals("TlsRsaPremasterSecret");
 384         Exception failover = null;
 385         byte[] encoded = null;
 386 
 387         update(wrappedKey, 0, wrappedKey.length);
 388         try {
 389             encoded = doFinal();
 390         } catch (BadPaddingException e) {
 391             if (isTlsRsaPremasterSecret) {
 392                 failover = e;
 393             } else {


< prev index next >