我编写了这段代码,我的密钥是:“ ooWqEPcw7KR / h / JIbrFCRHiEVaybvnB2”。
(?<!^|[A-Z\p{P}])[A-Z]|(?<=\p{P})\p{P}|(?<=\p{L})\d|(((?<!^)(?<!\p{P})[A-Z](?=[a-z]))|((?<=[a-z])[A-Z]))|(?<!^)(?=[[({&])|(?<=[)\]}!&}])
但是我得到这个错误!!!
try
{
Base64Decoder base64Decoder=new Base64Decoder();
String encryptType="DESede/ECB/PKCS5Padding";
String workingKey="ooWqEPcw7KR/h/JIbrFCRHiEVaybvnB2";
SecretKey secretKey=new SecretKeySpec(base64Decoder.decode(workingKey), encryptType);
Cipher cipher=Cipher.getInstance(encryptType);
cipher.init(1, secretKey);
}
catch(NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e)
{
e.printStackTrace();
}
答案 0 :(得分:1)
DESedeCrypt
类仅根据源代码支持DESede
和TripleDES
算法:
void init(boolean decrypting, String algorithm, byte[] keys)
throws InvalidKeyException {
if (!algorithm.equalsIgnoreCase("DESede")
&& !algorithm.equalsIgnoreCase("TripleDES")) {
throw new InvalidKeyException
("Wrong algorithm: DESede or TripleDES required");
}
您的代码必须使用SecretKey
中的两个之一。 Cipher
可以保留为DESede/ECB/PKCS5Padding
:
String workingKey = "ooWqEPcw7KR/h/JIbrFCRHiEVaybvnB2";
SecretKey secretKey = new SecretKeySpec(
Base64.getDecoder().decode(workingKey),
"DESede");
Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
cipher.init(1, secretKey);