I encountered a problem decoding text files.
Encryption works, but when the program is restarted, decryption throws an exception. The same similar Exception was thrown with apache.common.Base64.
Maybe someone knows how to solve this?
private String decrypt(String encrypted) throws Exception {
Cipher cipher = getCipher(Cipher.DECRYPT_MODE);
//byte[] plainBytes = cipher.doFinal(Base64.decodeBase64(encrypted));
/*this line throw an exception*/
byte[] plainBytes = cipher.doFinal(Base64.getDecoder().decode(encrypted));
return new String(plainBytes);
}
private Cipher getCipher(int cipherMode) throws Exception {
String encryptionAlgorithm = "AES";
SecretKeySpec keySpecification = new SecretKeySpec(
encryptionKey.getBytes("UTF-8"), encryptionAlgorithm);
Cipher cipher = Cipher.getInstance(encryptionAlgorithm);
cipher.init(cipherMode, keySpecification);
return cipher;
}
Exception in thread "main" java.lang.NullPointerException
at java.util.Base64$Decoder.decode(Base64.java:549)
at edmaker.EdMaker.decrypt(EdMaker.java:148)
Listening on javadebug Not able to submit breakpoint MethodBreakpoint [fsiteratetest.FsIterateTest$1].visitFile '(Ljava/nio/file/Path;LBasicFileAttributes;)Ljava/nio/file/FileVisitResult;', reason: Breakpoint belongs to disabled source root 'C:\Users\win7p\Documents\NetBeansProjects\FsIterateTest\src'. See Window/Debugging/Sources. User program running User program stopped Debugger stopped on uncompilable source code. User program running User program finished