javax.crypto.spec.DESKeySpec#DES_KEY_LEN源码实例Demo

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

源代码1 项目: jdk8u-jdk   文件: DESKeyGenerator.java
/**
 * 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;
}
 
源代码2 项目: jdk8u-dev-jdk   文件: DESKeyGenerator.java
/**
 * 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;
}
 
源代码3 项目: jdk8u60   文件: DESKeyGenerator.java
/**
 * 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;
}
 
源代码4 项目: jdk8u-jdk   文件: DESKeyGenerator.java
/**
 * 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;
}
 
源代码5 项目: jfxvnc   文件: VncAuthEncoder.java
private byte[] encryptPassword(VncAuthSecurityMessage msg) throws ProtocolException {
  if (msg.getChallenge().length != 16)
    throw new ProtocolException("invalid challenge length " + msg.getChallenge().length);
  try {
    byte[] keyBytes = new byte[DESKeySpec.DES_KEY_LEN];
    byte[] pwdBytes = String.valueOf(msg.getPassword()).getBytes(StandardCharsets.US_ASCII);

    for (int i = 0; i < keyBytes.length; i++) {
      keyBytes[i] = i < pwdBytes.length ? reverseBitsByte(pwdBytes[i]) : 0;
    }

    KeySpec desKeySpec = new DESKeySpec(keyBytes);
    SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("DES");
    SecretKey secretKey = secretKeyFactory.generateSecret(desKeySpec);
    Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
    cipher.init(Cipher.ENCRYPT_MODE, secretKey);

    return cipher.doFinal(msg.getChallenge());

  } catch (Exception e) {
    throw new ProtocolException("encrypt password failed", e);
  }
}
 
源代码6 项目: openjdk-jdk8u-backup   文件: DESKeyGenerator.java
/**
 * 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;
}
 
源代码7 项目: Bytecoder   文件: DESKeyGenerator.java
/**
 * 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;
}
 
源代码8 项目: jdk8u_jdk   文件: DESKeyGenerator.java
/**
 * 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;
}
 
源代码9 项目: openjdk-8   文件: DESKeyGenerator.java
/**
 * 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;
}
 
源代码10 项目: hottub   文件: DESKeyGenerator.java
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;
    }
}
 
源代码11 项目: TencentKona-8   文件: DESKeyGenerator.java
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;
    }
}
 
源代码12 项目: openjdk-8-source   文件: DESKeyGenerator.java
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;
    }
}
 
源代码13 项目: jdk8u-dev-jdk   文件: DESKeyGenerator.java
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;
    }
}
 
源代码14 项目: openjdk-jdk8u   文件: DESKeyGenerator.java
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;
    }
}
 
源代码15 项目: jdk8u-jdk   文件: DESKeyGenerator.java
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;
    }
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: DESKeyGenerator.java
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;
    }
}
 
源代码17 项目: Bytecoder   文件: DESKey.java
/**
 * 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));
}
 
源代码18 项目: jdk8u_jdk   文件: DESKeyGenerator.java
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;
    }
}
 
源代码19 项目: openjdk-jdk9   文件: DESKey.java
/**
 * 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);
}
 
源代码20 项目: openjdk-jdk8u-backup   文件: DESKey.java
/**
 * 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);
}