keytool.exe -genkey -alias juheon -keyalg RSA -keypass 1234qwer -storepass 1234qwer -keystore juheon.jks keytool.exe -export -alias juheon -storepass 1234qwer -file juheon.cer -keystore juheon.jks keytool.exe -importkeystore -srckeystore juheon.jks -destkeystore juheon.key.p12 -deststoretype PKCS12 D:\Java\32bit\jdk1.5.0_22\jre\lib\security\cacert D:\Java\32bit\jdk1.5.0_22\bin\keytool.exe -import -alias tsasample -keystore D:\Java\32bit\jdk1.5.0_22\jre\lib\security\cacert -file D:\workspace\Servers\tsa-server-web-config\tomcat.cer keytool -import -alias somansa -keystore C:\Program Files\Java\jdk1.8.0_102\jre\lib\security\cacert -file c:\somansa.cer #인증서 생성 keytool -genkey -alias keyAlias -keyalg RSA -keypass changeit -storepass changeit –validity 9999 -keystore keystore.jks keytool -export -alias keyAlias -storepass changeit -file server.cer -keystore keystore.jks keytool -import -v -trustcacerts -alias keyAlias -file server.cer ...
import java.security.InvalidKeyException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class Test {
private static SecretKeySpec key = null;
private static Cipher cipher = null;
private static void setUp() throws Exception {
byte[] bkey = "tjdehdrncjddkaghghkahebfzltkdlwm".getBytes();
key = new SecretKeySpec(bkey, "SEED");
cipher = Cipher.getInstance( "SEED/CBC/PKCS5Padding" );
}
public static void main(String [] args) throws Exception {
setUp();
byte [] encryptionBytes = null;
String input = "ABC123가나다";
System.out.println( "Entered: " + input );
encryptionBytes = encrypt( input );
BASE64Encoder encoder = new BASE64Encoder();
BASE64Decoder decoder = new BASE64Decoder();
String encodeString = encoder.encode(encryptionBytes);
System.out.println("Base64 Encode : " + encodeString);
System.out.println( "Recovered: " + decrypt( decoder.decodeBuffer(encodeString) ) );
}
private static byte [] encrypt(String input) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
cipher.init( Cipher.ENCRYPT_MODE, key );
byte [] inputBytes = input.getBytes();
return cipher.doFinal( inputBytes );
}
private static String decrypt(byte [] encryptionBytes) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
cipher.init( Cipher.DECRYPT_MODE, key );
byte [] recoveredBytes = cipher.doFinal( encryptionBytes );
String recovered = new String( recoveredBytes );
return recovered;
}
}
짜져 허렵아...
답글삭제완전 땡큐~~~~~~~~
삭제