当前位置: 首页>>代码示例>>Java>>正文


Java DESedeKeySpec.DES_EDE_KEY_LEN属性代码示例

本文整理汇总了Java中javax.crypto.spec.DESedeKeySpec.DES_EDE_KEY_LEN属性的典型用法代码示例。如果您正苦于以下问题:Java DESedeKeySpec.DES_EDE_KEY_LEN属性的具体用法?Java DESedeKeySpec.DES_EDE_KEY_LEN怎么用?Java DESedeKeySpec.DES_EDE_KEY_LEN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.crypto.spec.DESedeKeySpec的用法示例。


在下文中一共展示了DESedeKeySpec.DES_EDE_KEY_LEN属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: DESedeKey

/**
 * 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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:DESedeKey.java

示例2: doKeyGeneration

@Override
protected byte[] doKeyGeneration(int keyBytes) {
    byte[] keyData = new byte[DESedeKeySpec.DES_EDE_KEY_LEN];
    secureRandom.nextBytes(keyData);
    // Set the parity bit for each byte
    for (int i = 0; i < keyData.length; i++) {
        if (Integer.bitCount(keyData[i]) % 2 == 0) {
            keyData[i] = (byte) (keyData[i] ^ 1);
        }
    }
    if (keyBytes == 14) {
        // The user requested an A-B-A key
        System.arraycopy(keyData, 0, keyData, 16, 8);
    }
    return keyData;
}
 
开发者ID:google,项目名称:conscrypt,代码行数:16,代码来源:KeyGeneratorImpl.java

示例3: generateKeyData

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;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:8,代码来源:EncryptionTests.java

示例4: generateKeyData

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);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:15,代码来源:GenerateSecretKey.java

示例5: generateKeyData

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);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:14,代码来源:AlfrescoKeyStoreImpl.java

示例6: DESedeKey

/**
 * 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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:DESedeKey.java

示例7: engineGenerateKey

/**
 * 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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:44,代码来源:DESedeKeyGenerator.java

示例8: engineGenerateKey

/**
 * Generates the Triple DES key.
 *
 * @return the new Triple DES key
 */
protected SecretKey engineGenerateKey() {
    if (this.random == null) {
        this.random = SunJCE.RANDOM;
    }

    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;
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:44,代码来源:DESedeKeyGenerator.java


注:本文中的javax.crypto.spec.DESedeKeySpec.DES_EDE_KEY_LEN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。