javax.crypto.spec.DESedeKeySpec#DES_EDE_KEY_LEN源码实例Demo

下面列出了javax.crypto.spec.DESedeKeySpec#DES_EDE_KEY_LEN 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bytecoder   文件: DESedeKey.java
/**
 * Uses the first 24 bytes in <code>key</code>, beginning at
 * <code>offset</code>, as the DES-EDE key
 *
 * @param key the buffer with the DES-EDE key
 * @param offset the offset in <code>key</code>, where the DES-EDE key
 * starts
 *
 * @exception InvalidKeyException if the given key has a wrong size
 */
DESedeKey(byte[] key, int offset) throws InvalidKeyException {

    if (key==null || ((key.length-offset)<DESedeKeySpec.DES_EDE_KEY_LEN)) {
        throw new InvalidKeyException("Wrong key size");
    }
    this.key = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
    System.arraycopy(key, offset, this.key, 0,
                     DESedeKeySpec.DES_EDE_KEY_LEN);
    DESKeyGenerator.setParityBit(this.key, 0);
    DESKeyGenerator.setParityBit(this.key, 8);
    DESKeyGenerator.setParityBit(this.key, 16);

    // Use the cleaner to zero the key when no longer referenced
    final byte[] k = this.key;
    CleanerFactory.cleaner().register(this,
            () -> java.util.Arrays.fill(k, (byte)0x00));
}
 
源代码2 项目: jdk8u-dev-jdk   文件: DESedeKeyGenerator.java
/**
 * Generates the Triple DES key.
 *
 * @return the new Triple DES key
 */
protected SecretKey engineGenerateKey() {
    if (this.random == null) {
        this.random = SunJCE.getRandom();
    }

    byte[] rawkey = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];

    if (keysize == 168) {
        // 3 intermediate keys
        this.random.nextBytes(rawkey);

        // Do parity adjustment for each intermediate key
        DESKeyGenerator.setParityBit(rawkey, 0);
        DESKeyGenerator.setParityBit(rawkey, 8);
        DESKeyGenerator.setParityBit(rawkey, 16);
    } else {
        // 2 intermediate keys
        byte[] tmpkey = new byte[16];
        this.random.nextBytes(tmpkey);
        DESKeyGenerator.setParityBit(tmpkey, 0);
        DESKeyGenerator.setParityBit(tmpkey, 8);
        System.arraycopy(tmpkey, 0, rawkey, 0, tmpkey.length);
        // Copy the first 8 bytes into the last
        System.arraycopy(tmpkey, 0, rawkey, 16, 8);
        java.util.Arrays.fill(tmpkey, (byte)0x00);
    }

    DESedeKey desEdeKey = null;
    try {
        desEdeKey = new DESedeKey(rawkey);
    } catch (InvalidKeyException ike) {
        // this never happens
        throw new RuntimeException(ike.getMessage());
    }

    java.util.Arrays.fill(rawkey, (byte)0x00);

    return desEdeKey;
}
 
源代码3 项目: jdk8u-dev-jdk   文件: DESedeKey.java
/**
 * Uses the first 24 bytes in <code>key</code>, beginning at
 * <code>offset</code>, as the DES-EDE key
 *
 * @param key the buffer with the DES-EDE key
 * @param offset the offset in <code>key</code>, where the DES-EDE key
 * starts
 *
 * @exception InvalidKeyException if the given key has a wrong size
 */
DESedeKey(byte[] key, int offset) throws InvalidKeyException {

    if (key==null || ((key.length-offset)<DESedeKeySpec.DES_EDE_KEY_LEN)) {
        throw new InvalidKeyException("Wrong key size");
    }
    this.key = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
    System.arraycopy(key, offset, this.key, 0,
                     DESedeKeySpec.DES_EDE_KEY_LEN);
    DESKeyGenerator.setParityBit(this.key, 0);
    DESKeyGenerator.setParityBit(this.key, 8);
    DESKeyGenerator.setParityBit(this.key, 16);
}
 
源代码4 项目: TencentKona-8   文件: DESedeKey.java
/**
 * Uses the first 24 bytes in <code>key</code>, beginning at
 * <code>offset</code>, as the DES-EDE key
 *
 * @param key the buffer with the DES-EDE key
 * @param offset the offset in <code>key</code>, where the DES-EDE key
 * starts
 *
 * @exception InvalidKeyException if the given key has a wrong size
 */
DESedeKey(byte[] key, int offset) throws InvalidKeyException {

    if (key==null || ((key.length-offset)<DESedeKeySpec.DES_EDE_KEY_LEN)) {
        throw new InvalidKeyException("Wrong key size");
    }
    this.key = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
    System.arraycopy(key, offset, this.key, 0,
                     DESedeKeySpec.DES_EDE_KEY_LEN);
    DESKeyGenerator.setParityBit(this.key, 0);
    DESKeyGenerator.setParityBit(this.key, 8);
    DESKeyGenerator.setParityBit(this.key, 16);
}
 
源代码5 项目: jdk8u_jdk   文件: DESedeKeyGenerator.java
/**
 * Generates the Triple DES key.
 *
 * @return the new Triple DES key
 */
protected SecretKey engineGenerateKey() {
    if (this.random == null) {
        this.random = SunJCE.getRandom();
    }

    byte[] rawkey = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];

    if (keysize == 168) {
        // 3 intermediate keys
        this.random.nextBytes(rawkey);

        // Do parity adjustment for each intermediate key
        DESKeyGenerator.setParityBit(rawkey, 0);
        DESKeyGenerator.setParityBit(rawkey, 8);
        DESKeyGenerator.setParityBit(rawkey, 16);
    } else {
        // 2 intermediate keys
        byte[] tmpkey = new byte[16];
        this.random.nextBytes(tmpkey);
        DESKeyGenerator.setParityBit(tmpkey, 0);
        DESKeyGenerator.setParityBit(tmpkey, 8);
        System.arraycopy(tmpkey, 0, rawkey, 0, tmpkey.length);
        // Copy the first 8 bytes into the last
        System.arraycopy(tmpkey, 0, rawkey, 16, 8);
        java.util.Arrays.fill(tmpkey, (byte)0x00);
    }

    DESedeKey desEdeKey = null;
    try {
        desEdeKey = new DESedeKey(rawkey);
    } catch (InvalidKeyException ike) {
        // this never happens
        throw new RuntimeException(ike.getMessage());
    }

    java.util.Arrays.fill(rawkey, (byte)0x00);

    return desEdeKey;
}
 
源代码6 项目: jdk8u60   文件: DESedeKey.java
/**
 * Uses the first 24 bytes in <code>key</code>, beginning at
 * <code>offset</code>, as the DES-EDE key
 *
 * @param key the buffer with the DES-EDE key
 * @param offset the offset in <code>key</code>, where the DES-EDE key
 * starts
 *
 * @exception InvalidKeyException if the given key has a wrong size
 */
DESedeKey(byte[] key, int offset) throws InvalidKeyException {

    if (key==null || ((key.length-offset)<DESedeKeySpec.DES_EDE_KEY_LEN)) {
        throw new InvalidKeyException("Wrong key size");
    }
    this.key = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
    System.arraycopy(key, offset, this.key, 0,
                     DESedeKeySpec.DES_EDE_KEY_LEN);
    DESKeyGenerator.setParityBit(this.key, 0);
    DESKeyGenerator.setParityBit(this.key, 8);
    DESKeyGenerator.setParityBit(this.key, 16);
}
 
源代码7 项目: jdk8u60   文件: DESedeKeyGenerator.java
/**
 * Generates the Triple DES key.
 *
 * @return the new Triple DES key
 */
protected SecretKey engineGenerateKey() {
    if (this.random == null) {
        this.random = SunJCE.getRandom();
    }

    byte[] rawkey = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];

    if (keysize == 168) {
        // 3 intermediate keys
        this.random.nextBytes(rawkey);

        // Do parity adjustment for each intermediate key
        DESKeyGenerator.setParityBit(rawkey, 0);
        DESKeyGenerator.setParityBit(rawkey, 8);
        DESKeyGenerator.setParityBit(rawkey, 16);
    } else {
        // 2 intermediate keys
        byte[] tmpkey = new byte[16];
        this.random.nextBytes(tmpkey);
        DESKeyGenerator.setParityBit(tmpkey, 0);
        DESKeyGenerator.setParityBit(tmpkey, 8);
        System.arraycopy(tmpkey, 0, rawkey, 0, tmpkey.length);
        // Copy the first 8 bytes into the last
        System.arraycopy(tmpkey, 0, rawkey, 16, 8);
        java.util.Arrays.fill(tmpkey, (byte)0x00);
    }

    DESedeKey desEdeKey = null;
    try {
        desEdeKey = new DESedeKey(rawkey);
    } catch (InvalidKeyException ike) {
        // this never happens
        throw new RuntimeException(ike.getMessage());
    }

    java.util.Arrays.fill(rawkey, (byte)0x00);

    return desEdeKey;
}
 
源代码8 项目: jdk8u-jdk   文件: DESedeKey.java
/**
 * Uses the first 24 bytes in <code>key</code>, beginning at
 * <code>offset</code>, as the DES-EDE key
 *
 * @param key the buffer with the DES-EDE key
 * @param offset the offset in <code>key</code>, where the DES-EDE key
 * starts
 *
 * @exception InvalidKeyException if the given key has a wrong size
 */
DESedeKey(byte[] key, int offset) throws InvalidKeyException {

    if (key==null || ((key.length-offset)<DESedeKeySpec.DES_EDE_KEY_LEN)) {
        throw new InvalidKeyException("Wrong key size");
    }
    this.key = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
    System.arraycopy(key, offset, this.key, 0,
                     DESedeKeySpec.DES_EDE_KEY_LEN);
    DESKeyGenerator.setParityBit(this.key, 0);
    DESKeyGenerator.setParityBit(this.key, 8);
    DESKeyGenerator.setParityBit(this.key, 16);
}
 
源代码9 项目: openjdk-jdk8u   文件: DESedeKeyGenerator.java
/**
 * Generates the Triple DES key.
 *
 * @return the new Triple DES key
 */
protected SecretKey engineGenerateKey() {
    if (this.random == null) {
        this.random = SunJCE.getRandom();
    }

    byte[] rawkey = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];

    if (keysize == 168) {
        // 3 intermediate keys
        this.random.nextBytes(rawkey);

        // Do parity adjustment for each intermediate key
        DESKeyGenerator.setParityBit(rawkey, 0);
        DESKeyGenerator.setParityBit(rawkey, 8);
        DESKeyGenerator.setParityBit(rawkey, 16);
    } else {
        // 2 intermediate keys
        byte[] tmpkey = new byte[16];
        this.random.nextBytes(tmpkey);
        DESKeyGenerator.setParityBit(tmpkey, 0);
        DESKeyGenerator.setParityBit(tmpkey, 8);
        System.arraycopy(tmpkey, 0, rawkey, 0, tmpkey.length);
        // Copy the first 8 bytes into the last
        System.arraycopy(tmpkey, 0, rawkey, 16, 8);
        java.util.Arrays.fill(tmpkey, (byte)0x00);
    }

    DESedeKey desEdeKey = null;
    try {
        desEdeKey = new DESedeKey(rawkey);
    } catch (InvalidKeyException ike) {
        // this never happens
        throw new RuntimeException(ike.getMessage());
    }

    java.util.Arrays.fill(rawkey, (byte)0x00);

    return desEdeKey;
}
 
源代码10 项目: alfresco-repository   文件: EncryptionTests.java
public byte[] generateKeyData() throws NoSuchAlgorithmException
{
	SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
	random.setSeed(System.currentTimeMillis());
	byte bytes[] = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
	random.nextBytes(bytes);
	return bytes;
}
 
源代码11 项目: alfresco-repository   文件: KeyStoreTests.java
public byte[] generateKeyData() throws NoSuchAlgorithmException
{
	SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
	random.setSeed(System.currentTimeMillis());
	byte bytes[] = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
	random.nextBytes(bytes);
	return bytes;
}
 
源代码12 项目: alfresco-core   文件: GenerateSecretKey.java
public byte[] generateKeyData()
{
    try
    {
        SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
        random.setSeed(System.currentTimeMillis());
        byte bytes[] = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
        random.nextBytes(bytes);
        return bytes;
    }
    catch(Exception e)
    {
        throw new RuntimeException("Unable to generate secret key", e);
    }
}
 
源代码13 项目: alfresco-core   文件: AlfrescoKeyStoreImpl.java
private byte[] generateKeyData()
{
    try
    {
        SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
        byte bytes[] = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
        random.nextBytes(bytes);
        return bytes;
    }
    catch(Exception e)
    {
        throw new RuntimeException("Unable to generate secret key", e);
    }
}
 
源代码14 项目: openjdk-jdk8u-backup   文件: DESedeKey.java
/**
 * Uses the first 24 bytes in <code>key</code>, beginning at
 * <code>offset</code>, as the DES-EDE key
 *
 * @param key the buffer with the DES-EDE key
 * @param offset the offset in <code>key</code>, where the DES-EDE key
 * starts
 *
 * @exception InvalidKeyException if the given key has a wrong size
 */
DESedeKey(byte[] key, int offset) throws InvalidKeyException {

    if (key==null || ((key.length-offset)<DESedeKeySpec.DES_EDE_KEY_LEN)) {
        throw new InvalidKeyException("Wrong key size");
    }
    this.key = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
    System.arraycopy(key, offset, this.key, 0,
                     DESedeKeySpec.DES_EDE_KEY_LEN);
    DESKeyGenerator.setParityBit(this.key, 0);
    DESKeyGenerator.setParityBit(this.key, 8);
    DESKeyGenerator.setParityBit(this.key, 16);
}
 
源代码15 项目: openjdk-8   文件: DESedeKey.java
/**
 * Uses the first 24 bytes in <code>key</code>, beginning at
 * <code>offset</code>, as the DES-EDE key
 *
 * @param key the buffer with the DES-EDE key
 * @param offset the offset in <code>key</code>, where the DES-EDE key
 * starts
 *
 * @exception InvalidKeyException if the given key has a wrong size
 */
DESedeKey(byte[] key, int offset) throws InvalidKeyException {

    if (key==null || ((key.length-offset)<DESedeKeySpec.DES_EDE_KEY_LEN)) {
        throw new InvalidKeyException("Wrong key size");
    }
    this.key = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
    System.arraycopy(key, offset, this.key, 0,
                     DESedeKeySpec.DES_EDE_KEY_LEN);
    DESKeyGenerator.setParityBit(this.key, 0);
    DESKeyGenerator.setParityBit(this.key, 8);
    DESKeyGenerator.setParityBit(this.key, 16);
}
 
源代码16 项目: Bytecoder   文件: DESedeKeyGenerator.java
/**
 * Generates the Triple DES key.
 *
 * @return the new Triple DES key
 */
protected SecretKey engineGenerateKey() {
    if (this.random == null) {
        this.random = SunJCE.getRandom();
    }

    byte[] rawkey = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];

    if (keysize == 168) {
        // 3 intermediate keys
        this.random.nextBytes(rawkey);

        // Do parity adjustment for each intermediate key
        DESKeyGenerator.setParityBit(rawkey, 0);
        DESKeyGenerator.setParityBit(rawkey, 8);
        DESKeyGenerator.setParityBit(rawkey, 16);
    } else {
        // 2 intermediate keys
        byte[] tmpkey = new byte[16];
        this.random.nextBytes(tmpkey);
        DESKeyGenerator.setParityBit(tmpkey, 0);
        DESKeyGenerator.setParityBit(tmpkey, 8);
        System.arraycopy(tmpkey, 0, rawkey, 0, tmpkey.length);
        // Copy the first 8 bytes into the last
        System.arraycopy(tmpkey, 0, rawkey, 16, 8);
        java.util.Arrays.fill(tmpkey, (byte)0x00);
    }

    DESedeKey desEdeKey = null;
    try {
        desEdeKey = new DESedeKey(rawkey);
    } catch (InvalidKeyException ike) {
        // this never happens
        throw new RuntimeException(ike.getMessage());
    }

    java.util.Arrays.fill(rawkey, (byte)0x00);

    return desEdeKey;
}
 
源代码17 项目: openjdk-8-source   文件: DESedeKey.java
/**
 * Uses the first 24 bytes in <code>key</code>, beginning at
 * <code>offset</code>, as the DES-EDE key
 *
 * @param key the buffer with the DES-EDE key
 * @param offset the offset in <code>key</code>, where the DES-EDE key
 * starts
 *
 * @exception InvalidKeyException if the given key has a wrong size
 */
DESedeKey(byte[] key, int offset) throws InvalidKeyException {

    if (key==null || ((key.length-offset)<DESedeKeySpec.DES_EDE_KEY_LEN)) {
        throw new InvalidKeyException("Wrong key size");
    }
    this.key = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
    System.arraycopy(key, offset, this.key, 0,
                     DESedeKeySpec.DES_EDE_KEY_LEN);
    DESKeyGenerator.setParityBit(this.key, 0);
    DESKeyGenerator.setParityBit(this.key, 8);
    DESKeyGenerator.setParityBit(this.key, 16);
}
 
源代码18 项目: openjdk-jdk9   文件: DESedeKeyGenerator.java
/**
 * Generates the Triple DES key.
 *
 * @return the new Triple DES key
 */
protected SecretKey engineGenerateKey() {
    if (this.random == null) {
        this.random = SunJCE.getRandom();
    }

    byte[] rawkey = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];

    if (keysize == 168) {
        // 3 intermediate keys
        this.random.nextBytes(rawkey);

        // Do parity adjustment for each intermediate key
        DESKeyGenerator.setParityBit(rawkey, 0);
        DESKeyGenerator.setParityBit(rawkey, 8);
        DESKeyGenerator.setParityBit(rawkey, 16);
    } else {
        // 2 intermediate keys
        byte[] tmpkey = new byte[16];
        this.random.nextBytes(tmpkey);
        DESKeyGenerator.setParityBit(tmpkey, 0);
        DESKeyGenerator.setParityBit(tmpkey, 8);
        System.arraycopy(tmpkey, 0, rawkey, 0, tmpkey.length);
        // Copy the first 8 bytes into the last
        System.arraycopy(tmpkey, 0, rawkey, 16, 8);
        java.util.Arrays.fill(tmpkey, (byte)0x00);
    }

    DESedeKey desEdeKey = null;
    try {
        desEdeKey = new DESedeKey(rawkey);
    } catch (InvalidKeyException ike) {
        // this never happens
        throw new RuntimeException(ike.getMessage());
    }

    java.util.Arrays.fill(rawkey, (byte)0x00);

    return desEdeKey;
}
 
源代码19 项目: jdk8u-jdk   文件: DESedeKey.java
/**
 * Uses the first 24 bytes in <code>key</code>, beginning at
 * <code>offset</code>, as the DES-EDE key
 *
 * @param key the buffer with the DES-EDE key
 * @param offset the offset in <code>key</code>, where the DES-EDE key
 * starts
 *
 * @exception InvalidKeyException if the given key has a wrong size
 */
DESedeKey(byte[] key, int offset) throws InvalidKeyException {

    if (key==null || ((key.length-offset)<DESedeKeySpec.DES_EDE_KEY_LEN)) {
        throw new InvalidKeyException("Wrong key size");
    }
    this.key = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
    System.arraycopy(key, offset, this.key, 0,
                     DESedeKeySpec.DES_EDE_KEY_LEN);
    DESKeyGenerator.setParityBit(this.key, 0);
    DESKeyGenerator.setParityBit(this.key, 8);
    DESKeyGenerator.setParityBit(this.key, 16);
}
 
源代码20 项目: jdk8u-jdk   文件: DESedeKeyGenerator.java
/**
 * Generates the Triple DES key.
 *
 * @return the new Triple DES key
 */
protected SecretKey engineGenerateKey() {
    if (this.random == null) {
        this.random = SunJCE.getRandom();
    }

    byte[] rawkey = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];

    if (keysize == 168) {
        // 3 intermediate keys
        this.random.nextBytes(rawkey);

        // Do parity adjustment for each intermediate key
        DESKeyGenerator.setParityBit(rawkey, 0);
        DESKeyGenerator.setParityBit(rawkey, 8);
        DESKeyGenerator.setParityBit(rawkey, 16);
    } else {
        // 2 intermediate keys
        byte[] tmpkey = new byte[16];
        this.random.nextBytes(tmpkey);
        DESKeyGenerator.setParityBit(tmpkey, 0);
        DESKeyGenerator.setParityBit(tmpkey, 8);
        System.arraycopy(tmpkey, 0, rawkey, 0, tmpkey.length);
        // Copy the first 8 bytes into the last
        System.arraycopy(tmpkey, 0, rawkey, 16, 8);
        java.util.Arrays.fill(tmpkey, (byte)0x00);
    }

    DESedeKey desEdeKey = null;
    try {
        desEdeKey = new DESedeKey(rawkey);
    } catch (InvalidKeyException ike) {
        // this never happens
        throw new RuntimeException(ike.getMessage());
    }

    java.util.Arrays.fill(rawkey, (byte)0x00);

    return desEdeKey;
}