package runtime;
import java.security.Security;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class RutimeTest {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
byte[] input = "1234567890".getBytes();
byte[] keyBytes = "input123".getBytes();
SecretKeySpec key = new SecretKeySpec(keyBytes, "ARC4");
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
Cipher cipher = Cipher.getInstance("ARC4", "BC");
//인코딩
byte[] cipherText = new byte[input.length];
cipher.init(Cipher.ENCRYPT_MODE, key);
int ctLength = cipher.update(input, 0, input.length, cipherText, 0);
ctLength += cipher.doFinal(cipherText, ctLength);
System.out.println("cipher text: " + new String(cipherText));
//디코딩
byte[] plainText = new byte[ctLength];
cipher.init(Cipher.DECRYPT_MODE, key);
int ptLength = cipher.update(cipherText, 0, ctLength, plainText, 0);
ptLength += cipher.doFinal(plainText, ptLength);
System.out.println("plain text : " + new String(plainText));
}
}
라이브러리 다운받고해야됨
bcprov/bcprov-jdk15on-1.52.jar.zip( 2,482 k)
'JAVA > 자바' 카테고리의 다른 글
자바 JFileChooser (0) | 2016.02.10 |
---|---|
자바 오류 (0) | 2015.11.21 |
자바 멀티파트 (0) | 2015.11.02 |
자바 스트림 종류 (0) | 2015.10.29 |
자바 이미지파일 전송 클라이언트쪽 (0) | 2015.10.29 |