< prev index next >

src/java.base/share/classes/javax/crypto/SecretKeyFactory.java

Print this page


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


  35 import sun.security.jca.GetInstance.Instance;
  36 
  37 /**
  38  * This class represents a factory for secret keys.
  39  *
  40  * <P> Key factories are used to convert <I>keys</I> (opaque
  41  * cryptographic keys of type {@code Key}) into <I>key specifications</I>
  42  * (transparent representations of the underlying key material), and vice
  43  * versa.
  44  * Secret key factories operate only on secret (symmetric) keys.
  45  *
  46  * <P> Key factories are bi-directional, i.e., they allow to build an opaque
  47  * key object from a given key specification (key material), or to retrieve
  48  * the underlying key material of a key object in a suitable format.
  49  *
  50  * <P> Application developers should refer to their provider's documentation
  51  * to find out which key specifications are supported by the
  52  * {@link #generateSecret(java.security.spec.KeySpec) generateSecret} and
  53  * {@link #getKeySpec(javax.crypto.SecretKey, java.lang.Class) getKeySpec}
  54  * methods.
  55  * For example, the DES secret-key factory supplied by the "SunJCE" provider
  56  * supports {@code DESKeySpec} as a transparent representation of DES
  57  * keys, and that provider's secret-key factory for Triple DES keys supports
  58  * {@code DESedeKeySpec} as a transparent representation of Triple DES
  59  * keys.
  60  *
  61  * <p> Every implementation of the Java platform is required to support the
  62  * following standard {@code SecretKeyFactory} algorithms:
  63  * <ul>
  64  * <li>{@code DES}</li>
  65  * <li>{@code DESede}</li>
  66  * </ul>
  67  * These algorithms are described in the <a href=
  68  * "{@docRoot}/../specs/security/standard-names.html#secretkeyfactory-algorithms">
  69  * SecretKeyFactory section</a> of the
  70  * Java Security Standard Algorithm Names Specification.
  71  * Consult the release documentation for your implementation to see if any
  72  * other algorithms are supported.
  73  *
  74  * @author Jan Luehe
  75  *
  76  * @see SecretKey
  77  * @see javax.crypto.spec.DESKeySpec
  78  * @see javax.crypto.spec.DESedeKeySpec
  79  * @see javax.crypto.spec.PBEKeySpec
  80  * @since 1.4
  81  */
  82 
  83 public class SecretKeyFactory {
  84 
  85     // The provider
  86     private Provider provider;
  87 
  88     // The algorithm associated with this factory
  89     private final String algorithm;
  90 
  91     // The provider implementation (delegate)
  92     private volatile SecretKeyFactorySpi spi;
  93 
  94     // lock for mutex during provider selection
  95     private final Object lock = new Object();
  96 
  97     // remaining services to try in provider selection


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


  35 import sun.security.jca.GetInstance.Instance;
  36 
  37 /**
  38  * This class represents a factory for secret keys.
  39  *
  40  * <P> Key factories are used to convert <I>keys</I> (opaque
  41  * cryptographic keys of type {@code Key}) into <I>key specifications</I>
  42  * (transparent representations of the underlying key material), and vice
  43  * versa.
  44  * Secret key factories operate only on secret (symmetric) keys.
  45  *
  46  * <P> Key factories are bi-directional, i.e., they allow to build an opaque
  47  * key object from a given key specification (key material), or to retrieve
  48  * the underlying key material of a key object in a suitable format.
  49  *
  50  * <P> Application developers should refer to their provider's documentation
  51  * to find out which key specifications are supported by the
  52  * {@link #generateSecret(java.security.spec.KeySpec) generateSecret} and
  53  * {@link #getKeySpec(javax.crypto.SecretKey, java.lang.Class) getKeySpec}
  54  * methods.
  55  * For example, the DESede (Triple DES) secret-key factory supplied by the
  56  * "SunJCE" provider supports {@code DESedeKeySpec} as a transparent
  57  * representation of Triple DES keys.


  58  *
  59  * <p> Every implementation of the Java platform is required to support the
  60  * following standard {@code SecretKeyFactory} algorithms:
  61  * <ul>

  62  * <li>{@code DESede}</li>
  63  * </ul>
  64  * These algorithms are described in the <a href=
  65  * "{@docRoot}/../specs/security/standard-names.html#secretkeyfactory-algorithms">
  66  * SecretKeyFactory section</a> of the
  67  * Java Security Standard Algorithm Names Specification.
  68  * Consult the release documentation for your implementation to see if any
  69  * other algorithms are supported.
  70  *
  71  * @author Jan Luehe
  72  *
  73  * @see SecretKey

  74  * @see javax.crypto.spec.DESedeKeySpec
  75  * @see javax.crypto.spec.PBEKeySpec
  76  * @since 1.4
  77  */
  78 
  79 public class SecretKeyFactory {
  80 
  81     // The provider
  82     private Provider provider;
  83 
  84     // The algorithm associated with this factory
  85     private final String algorithm;
  86 
  87     // The provider implementation (delegate)
  88     private volatile SecretKeyFactorySpi spi;
  89 
  90     // lock for mutex during provider selection
  91     private final Object lock = new Object();
  92 
  93     // remaining services to try in provider selection


< prev index next >