jdk/src/java.base/share/classes/javax/crypto/spec/SecretKeySpec.java
author valeriep
Mon, 06 Apr 2015 20:24:27 +0000
changeset 31695 4d10942c9a7b
parent 25859 3317bb8137f4
child 45665 6f21cd7ec80e
permissions -rw-r--r--
8074865: General crypto resilience changes Summary: Replaced Arrays.equals() with MessageDigest.isEqual() when comparing sensitive values Reviewed-by: mullan, xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
31695
4d10942c9a7b 8074865: General crypto resilience changes
valeriep
parents: 25859
diff changeset
     2
 * Copyright (c) 1998, 2015, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 javax.crypto.spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
31695
4d10942c9a7b 8074865: General crypto resilience changes
valeriep
parents: 25859
diff changeset
    28
import java.security.MessageDigest;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.spec.KeySpec;
25402
0c24d9aa8fb9 7065233: To interpret case-insensitive string locale independently
juh
parents: 23010
diff changeset
    30
import java.util.Locale;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.crypto.SecretKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This class specifies a secret key in a provider-independent fashion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>It can be used to construct a <code>SecretKey</code> from a byte array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * without having to go through a (provider-based)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <code>SecretKeyFactory</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>This class is only useful for raw secret keys that can be represented as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * a byte array and have no key parameters associated with them, e.g., DES or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Triple DES keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @see javax.crypto.SecretKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @see javax.crypto.SecretKeyFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class SecretKeySpec implements KeySpec, SecretKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static final long serialVersionUID = 6577238317307289933L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * The secret key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private byte[] key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * The name of the algorithm associated with this key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private String algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Constructs a secret key from the given byte array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * <p>This constructor does not check if the given bytes indeed specify a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * secret key of the specified algorithm. For example, if the algorithm is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * DES, this constructor does not check if <code>key</code> is 8 bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * long, and also does not check for weak or semi-weak keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * In order for those checks to be performed, an algorithm-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <i>key specification</i> class (in this case:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * {@link DESKeySpec DESKeySpec})
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * should be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param key the key material of the secret key. The contents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * the array are copied to protect against subsequent modification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param algorithm the name of the secret-key algorithm to be associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * with the given key material.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *   "{@docRoot}/../technotes/guides/security/crypto/CryptoSpec.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Java Cryptography Architecture Reference Guide</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @exception IllegalArgumentException if <code>algorithm</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * is null or <code>key</code> is null or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public SecretKeySpec(byte[] key, String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (key == null || algorithm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            throw new IllegalArgumentException("Missing argument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (key.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            throw new IllegalArgumentException("Empty key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
    98
        this.key = key.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Constructs a secret key from the given byte array, using the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * <code>len</code> bytes of <code>key</code>, starting at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * <code>offset</code> inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * <p> The bytes that constitute the secret key are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * those between <code>key[offset]</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <code>key[offset+len-1]</code> inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <p>This constructor does not check if the given bytes indeed specify a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * secret key of the specified algorithm. For example, if the algorithm is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * DES, this constructor does not check if <code>key</code> is 8 bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * long, and also does not check for weak or semi-weak keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * In order for those checks to be performed, an algorithm-specific key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * specification class (in this case:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * {@link DESKeySpec DESKeySpec})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * must be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param key the key material of the secret key. The first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * <code>len</code> bytes of the array beginning at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * <code>offset</code> inclusive are copied to protect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * against subsequent modification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param offset the offset in <code>key</code> where the key material
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * starts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param len the length of the key material.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param algorithm the name of the secret-key algorithm to be associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * with the given key material.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *   "{@docRoot}/../technotes/guides/security/crypto/CryptoSpec.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Java Cryptography Architecture Reference Guide</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @exception IllegalArgumentException if <code>algorithm</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * is null or <code>key</code> is null, empty, or too short,
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 10336
diff changeset
   135
     * i.e. {@code key.length-offset<len}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @exception ArrayIndexOutOfBoundsException is thrown if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * <code>offset</code> or <code>len</code> index bytes outside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <code>key</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public SecretKeySpec(byte[] key, int offset, int len, String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (key == null || algorithm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            throw new IllegalArgumentException("Missing argument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (key.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            throw new IllegalArgumentException("Empty key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (key.length-offset < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                ("Invalid offset/length combination");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (len < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            throw new ArrayIndexOutOfBoundsException("len is negative");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        this.key = new byte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        System.arraycopy(key, offset, this.key, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Returns the name of the algorithm associated with this secret key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @return the secret key algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Returns the name of the encoding format for this secret key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @return the string "RAW".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return "RAW";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Returns the key material of this secret key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @return the key material. Returns a new array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * each time this method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public byte[] getEncoded() {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   184
        return this.key.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Calculates a hash code value for the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Objects that are equal will also have the same hashcode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        int retval = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        for (int i = 1; i < this.key.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            retval += this.key[i] * i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (this.algorithm.equalsIgnoreCase("TripleDES"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            return (retval ^= "desede".hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        else
25402
0c24d9aa8fb9 7065233: To interpret case-insensitive string locale independently
juh
parents: 23010
diff changeset
   199
            return (retval ^=
0c24d9aa8fb9 7065233: To interpret case-insensitive string locale independently
juh
parents: 23010
diff changeset
   200
                    this.algorithm.toLowerCase(Locale.ENGLISH).hashCode());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Tests for equality between the specified object and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * object. Two SecretKeySpec objects are considered equal if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * they are both SecretKey instances which have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * same case-insensitive algorithm name and key encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param obj the object to test for equality with this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return true if the objects are considered equal, false if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * <code>obj</code> is null or otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        if (this == obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (!(obj instanceof SecretKey))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        String thatAlg = ((SecretKey)obj).getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (!(thatAlg.equalsIgnoreCase(this.algorithm))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            if ((!(thatAlg.equalsIgnoreCase("DESede"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                 || !(this.algorithm.equalsIgnoreCase("TripleDES")))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                && (!(thatAlg.equalsIgnoreCase("TripleDES"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    || !(this.algorithm.equalsIgnoreCase("DESede"))))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        byte[] thatKey = ((SecretKey)obj).getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
31695
4d10942c9a7b 8074865: General crypto resilience changes
valeriep
parents: 25859
diff changeset
   232
        return MessageDigest.isEqual(this.key, thatKey);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
}