Created
October 23, 2018 08:00
-
-
Save sogatanco/07ca19fd8deef935842926f170fbef0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package encript; | |
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.OutputStream; | |
import java.nio.file.Files; | |
import java.security.InvalidKeyException; | |
import java.security.NoSuchAlgorithmException; | |
import javax.crypto.BadPaddingException; | |
import javax.crypto.Cipher; | |
import javax.crypto.IllegalBlockSizeException; | |
import javax.crypto.NoSuchPaddingException; | |
import javax.crypto.spec.SecretKeySpec; | |
/** | |
* | |
* @author ACER | |
*/ | |
public class Encript { | |
/** | |
* @param args the command line arguments | |
* @throws java.io.IOException | |
* @throws java.security.NoSuchAlgorithmException | |
* @throws javax.crypto.NoSuchPaddingException | |
* @throws java.security.InvalidKeyException | |
* @throws javax.crypto.IllegalBlockSizeException | |
* @throws javax.crypto.BadPaddingException | |
*/ | |
public static void main(String[] args)throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { | |
byte[] array = Files.readAllBytes(new File("D:\\before.txt").toPath()); | |
byte [] secKey=new byte[]{'1','2','3','4','m','m','a','d','r','i','z','k','a','a','j','0'}; | |
SecretKeySpec aesKey=new SecretKeySpec(secKey,"AES"); | |
Cipher cipher= Cipher.getInstance("AES/ECB/PKCS5Padding"); | |
cipher.init(Cipher.ENCRYPT_MODE, aesKey); | |
byte[] encrypted = cipher.doFinal(array); | |
OutputStream out=new FileOutputStream("D:\\chiper.txt"); | |
out.write(encrypted); | |
byte[] cipherFile = Files.readAllBytes(new File("D:\\chiper.txt").toPath()); | |
cipher.init(Cipher.DECRYPT_MODE, aesKey); | |
byte[] dekripsi = cipher.doFinal(cipherFile); | |
OutputStream outputDekripsi=new FileOutputStream("D:\\dekriptedfile.txt"); | |
outputDekripsi.write(dekripsi); | |
out.flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment