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


Java DESKeySpec.DES_KEY_LEN属性代码示例

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


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

示例1: engineGenerateKey

/**
 * Generates the DES key.
 *
 * @return the new DES key
 */
protected SecretKey engineGenerateKey() {
    DESKey desKey = null;

    if (this.random == null) {
        this.random = SunJCE.getRandom();
    }

    try {
        byte[] key = new byte[DESKeySpec.DES_KEY_LEN];
        do {
            this.random.nextBytes(key);
            setParityBit(key, 0);
        } while (DESKeySpec.isWeak(key, 0));
        desKey = new DESKey(key);
    } catch (InvalidKeyException e) {
        // this is never thrown
    }

    return desKey;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:DESKeyGenerator.java

示例2: setParityBit

static void setParityBit(byte[] key, int offset) {
    if (key == null)
        return;

    for (int i = 0; i < DESKeySpec.DES_KEY_LEN; i++) {
        int b = key[offset] & 0xfe;
        b |= (Integer.bitCount(b) & 1) ^ 1;
        key[offset++] = (byte)b;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:DESKeyGenerator.java

示例3: DESKey

/**
 * Uses the first 8 bytes in <code>key</code>, beginning at
 * <code>offset</code>, as the DES key
 *
 * @param key the buffer with the DES key bytes.
 * @param offset the offset in <code>key</code>, where the DES key bytes
 * start.
 *
 * @exception InvalidKeyException if less than 8 bytes are available for
 * the key.
 */
DESKey(byte[] key, int offset) throws InvalidKeyException {
    if (key == null || key.length - offset < DESKeySpec.DES_KEY_LEN) {
        throw new InvalidKeyException("Wrong key size");
    }
    this.key = new byte[DESKeySpec.DES_KEY_LEN];
    System.arraycopy(key, offset, this.key, 0, DESKeySpec.DES_KEY_LEN);
    DESKeyGenerator.setParityBit(this.key, 0);

    // 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,代码行数:24,代码来源:DESKey.java

示例4: DESKey

/**
 * Uses the first 8 bytes in <code>key</code>, beginning at
 * <code>offset</code>, as the DES key
 *
 * @param key the buffer with the DES key bytes.
 * @param offset the offset in <code>key</code>, where the DES key bytes
 * start.
 *
 * @exception InvalidKeyException if less than 8 bytes are available for
 * the key.
 */
DESKey(byte[] key, int offset) throws InvalidKeyException {
    if (key == null || key.length - offset < DESKeySpec.DES_KEY_LEN) {
        throw new InvalidKeyException("Wrong key size");
    }
    this.key = new byte[DESKeySpec.DES_KEY_LEN];
    System.arraycopy(key, offset, this.key, 0, DESKeySpec.DES_KEY_LEN);
    DESKeyGenerator.setParityBit(this.key, 0);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:DESKey.java


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