3DES 암호 화 복호화
package com.dc;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
/* ****************** *********************
* class : DcDES3Util
* @author : ncc
* create time : 2017-12-19 10:01:53
* @version : 1.0
* description : 3DES Triple DES, DES , 3 56 3DES
* 。 (DES) ,
* , 1981 ANSI ANSI X.3.92。
* DES 56 , , 64
* 。 DES,3DES 。 3DES( Triple DES)
* DES AES (1999 ,NIST 3-DES ),
* DES 。 DES , ,
* :
* Ek() Dk() DES ,K DES ,P ,C ,
* ,3DES :C=Ek3(Dk2(Ek1(P)))
* 3DES :P=Dk1((EK2(Dk3(C)))
* @see :
* ************************************************/
public class DcDES3Util {
// KeyGenerator ,
private KeyGenerator keygen;
// SecretKey
private SecretKey deskey;
// Cipher
private Cipher c;
//
private byte[] cipherByte;
/**
* @throws NoSuchAlgorithmException
* @throws NoSuchPaddingException
*/
public DcDES3Util() throws NoSuchAlgorithmException, NoSuchPaddingException {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
// DES ( , )
keygen = KeyGenerator.getInstance("DESede");
//
deskey = keygen.generateKey();
// Cipher , DES
c = Cipher.getInstance("DESede");
}
/* ********************************************
* method name : Encrytor
* description :
* @return : byte[]
* @param : @param str
* @param : @return
* @param : @throws InvalidKeyException
* @param : @throws IllegalBlockSizeException
* @param : @throws BadPaddingException
* modified : ncc , 2017-12-19
* @see :
* ********************************************/
public byte[] Encrytor(String str) throws InvalidKeyException,
IllegalBlockSizeException, BadPaddingException {
// , Cipher ,ENCRYPT_MODE
c.init(Cipher.ENCRYPT_MODE, deskey);
byte[] src = str.getBytes();
// , cipherByte
cipherByte = c.doFinal(src);
return cipherByte;
}
/* ********************************************
* method name : Decryptor
* description :
* @return : byte[]
* @param : @param buff
* @param : @return
* @param : @throws InvalidKeyException
* @param : @throws IllegalBlockSizeException
* @param : @throws BadPaddingException
* modified : ncc , 2017-12-19
* @see :
* ********************************************/
public byte[] Decryptor(byte[] buff) throws InvalidKeyException,
IllegalBlockSizeException, BadPaddingException {
// , Cipher ,DECRYPT_MODE
c.init(Cipher.DECRYPT_MODE, deskey);
cipherByte = c.doFinal(buff);
return cipherByte;
}
/**
* @param args
* @throws NoSuchPaddingException
* @throws NoSuchAlgorithmException
* @throws BadPaddingException
* @throws IllegalBlockSizeException
* @throws InvalidKeyException
*/
public static void main(String[] args) throws Exception {
DcDES3Util des3 = new DcDES3Util();
String msg =" !";
byte[] encontent = des3.Encrytor(msg);
byte[] decontent = des3.Decryptor(encontent);
System.out.println(" :" + msg);
System.out.println(" :" + new String(encontent));
System.out.println(" :" + new String(decontent));
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
자바 대칭 암호 화 몇 가지 알고리즘 각각 실현자바 대칭 암호 화 는 DES/3DES/AES 라 는 세 가지 알고리즘 을 각각 사용 하여 이 루어 집 니 다. 주의 하 세 요.이것 은 제 가 말 한 것 이 아니 라 수많은 프로그래머 들 이 정리 한 것 입 니 다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.