|
Java example source code file (DESKeySpec.java)
The DESKeySpec.java Java example source code/* * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.crypto.spec; import java.security.InvalidKeyException; /** * This class specifies a DES key. * * @author Jan Luehe * * @since 1.4 */ public class DESKeySpec implements java.security.spec.KeySpec { /** * The constant which defines the length of a DES key in bytes. */ public static final int DES_KEY_LEN = 8; private byte[] key; /* * Weak/semi-weak keys copied from FIPS 74. * * "...The first 6 keys have duals different than themselves, hence * each is both a key and a dual giving 12 keys with duals. The last * four keys equal their duals, and are called self-dual keys..." * * 1. E001E001F101F101 01E001E001F101F1 * 2. FE1FFE1FFEOEFEOE 1FFE1FFEOEFEOEFE * 3. E01FE01FF10EF10E 1FE01FEOOEF10EF1 * 4. 01FE01FE01FE01FE FE01FE01FE01FE01 * 5. 011F011F010E010E 1F011F010E010E01 * 6. E0FEE0FEF1FEF1FE FEE0FEE0FEF1FEF1 * 7. 0101010101010101 0101010101010101 * 8. FEFEFEFEFEFEFEFE FEFEFEFEFEFEFEFE * 9. E0E0E0E0F1F1F1F1 E0E0E0E0F1F1F1F1 * 10. 1F1F1F1F0E0E0E0E 1F1F1F1F0E0E0E0E */ private static final byte[][] WEAK_KEYS = { { (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01 }, { (byte)0xFE, (byte)0xFE, (byte)0xFE, (byte)0xFE, (byte)0xFE, (byte)0xFE, (byte)0xFE, (byte)0xFE }, { (byte)0x1F, (byte)0x1F, (byte)0x1F, (byte)0x1F, (byte)0x0E, (byte)0x0E, (byte)0x0E, (byte)0x0E }, { (byte)0xE0, (byte)0xE0, (byte)0xE0, (byte)0xE0, (byte)0xF1, (byte)0xF1, (byte)0xF1, (byte)0xF1 }, { (byte)0x01, (byte)0xFE, (byte)0x01, (byte)0xFE, (byte)0x01, (byte)0xFE, (byte)0x01, (byte)0xFE }, { (byte)0x1F, (byte)0xE0, (byte)0x1F, (byte)0xE0, (byte)0x0E, (byte)0xF1, (byte)0x0E, (byte)0xF1 }, { (byte)0x01, (byte)0xE0, (byte)0x01, (byte)0xE0, (byte)0x01, (byte)0xF1, (byte)0x01, (byte)0xF1 }, { (byte)0x1F, (byte)0xFE, (byte)0x1F, (byte)0xFE, (byte)0x0E, (byte)0xFE, (byte)0x0E, (byte)0xFE }, { (byte)0x01, (byte)0x1F, (byte)0x01, (byte)0x1F, (byte)0x01, (byte)0x0E, (byte)0x01, (byte)0x0E }, { (byte)0xE0, (byte)0xFE, (byte)0xE0, (byte)0xFE, (byte)0xF1, (byte)0xFE, (byte)0xF1, (byte)0xFE }, { (byte)0xFE, (byte)0x01, (byte)0xFE, (byte)0x01, (byte)0xFE, (byte)0x01, (byte)0xFE, (byte)0x01 }, { (byte)0xE0, (byte)0x1F, (byte)0xE0, (byte)0x1F, (byte)0xF1, (byte)0x0E, (byte)0xF1, (byte)0x0E }, { (byte)0xE0, (byte)0x01, (byte)0xE0, (byte)0x01, (byte)0xF1, (byte)0x01, (byte)0xF1, (byte)0x01 }, { (byte)0xFE, (byte)0x1F, (byte)0xFE, (byte)0x1F, (byte)0xFE, (byte)0x0E, (byte)0xFE, (byte)0x0E }, { (byte)0x1F, (byte)0x01, (byte)0x1F, (byte)0x01, (byte)0x0E, (byte)0x01, (byte)0x0E, (byte)0x01 }, { (byte)0xFE, (byte)0xE0, (byte)0xFE, (byte)0xE0, (byte)0xFE, (byte)0xF1, (byte)0xFE, (byte)0xF1 } }; /** * Creates a DESKeySpec object using the first 8 bytes in * <code>key as the key material for the DES key. * * <p> The bytes that constitute the DES key are those between * <code>key[0] and Other Java examples (source code examples)Here is a short list of links related to this Java DESKeySpec.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.