我正在尝试使用AES算法编写一个简单的程序来加密和解密文件.我没有加密问题,但解密..
public static void main(String[] args) throws NoSuchAlgorithmException, FileNotFoundException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {
// ????????????? ????????? ??????
KeyGenerator keyGenS = KeyGenerator.getInstance("AES");
keyGenS.init(128);
SecretKey sKey1 = keyGenS.generateKey();
SecretKey sKey2 = keyGenS.generateKey();
// ??????? ????????? ?????? ? ?????? ? ?????? ? ????
String key1 = SecretKeyToString(sKey1);
String key2 = SecretKeyToString(sKey2);
spreader.write(fileName1, key1);
spreader.write(fileName2, key2);
spreader.write(fileNameS1, key1);
spreader.write(fileNameS2, key2);
// ?????? ????????? ?????? ?? ????? ? ??????? ??????? ? ??? SecretKey
key1 = spreader.read(fileName1);
System.out.println("????????? ???? 1?? ????????????: " +key1);
SecretKey seansKey1=getKeyInstance(key1); …Run Code Online (Sandbox Code Playgroud)