加密时报InvalidKeyException问题

来源:互联网 发布:世界征服者3mac破解版 编辑:程序博客网 时间:2024/04/30 05:24

1.

使用DESedeKeySpec类时,抛了一个异常:InvalidKeyException!
看这个类的源码时才知道:/**
* Creates a new <code>DESedeKeySpec</code> instance from the first 24 (
* {@link #DES_EDE_KEY_LEN}) bytes of the specified key data.
*
* @param key
* the key data.
* @throws InvalidKeyException
* if the length of the key data is less than 24.
* @throws NullPointerException
* if the key data is null.
*/
public DESedeKeySpec(byte[] key) throws InvalidKeyException {
if (key == null) {
throw new NullPointerException("key == null");
}
if (key.length < DES_EDE_KEY_LEN) {
throw new InvalidKeyException();
}
this.key = new byte[DES_EDE_KEY_LEN];
System.arraycopy(key, 0, this.key, 0, DES_EDE_KEY_LEN);
}

代码注释中有句话 if the length of the key data is less than 24会抛异常throws InvalidKeyException ,也就是私钥的长度不能小于24位!

2.

公钥IvParameterSpec的长度必须是8位

0 0
原创粉丝点击