本文整理汇总了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;
}
示例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;
}
}
示例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));
}
示例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);
}