일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- oracle
- Excel
- 오라클
- 마이플랫폼
- 기타소득
- 에러
- 데이터베이스
- 이클립스
- JEUS
- 톰캣
- Tomcat
- Eclipse
- 오류
- 엑셀
- 한글
- DB
- 자바
- 성능
- JavaScript
- 튜닝
- 함수
- MIP
- Report Designer
- 태그를 입력해 주세요.
- 회계
- miplatform
- error
- java
- Book
- 도서
Archives
- Today
- Total
어느 가을날의 전환점
보안|개인정보 보호 및 암호화 본문
1. 단방향 암호화: SHA-512 알고리즘 사용
- 대상: 비밀번호
2. 양방향 암호화: AES256 알고리즘 사용
|
JAVA AES256 알고리즘
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.io.*;
import java.security.NoSuchAlgorithmException;
public class AES256 {
public static SecretKeySpec getKeySpec() throws IOException, NoSuchAlgorithmException {
byte[] bytes = new byte[32];
SecretKey key = null;
SecretKeySpec spec = null;
/*
File f = new File("aes_key");
if (f.exists()) {
new FileInputStream(f).read(bytes);
} else {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(256);
key = kgen.generateKey();
bytes1 = key.getEncoded();
new FileOutputStream(f).write(bytes1);
}
*/
String keyStr="암호화된 대칭키";
bytes = Base64Utils.base64Decode(keyStr);
spec = new SecretKeySpec(bytes,"AES");
return spec;
}
public String encrypt(String text) throws Exception {
SecretKeySpec spec = getKeySpec();
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, spec);
BASE64Encoder enc = new BASE64Encoder();
return enc.encode(cipher.doFinal(text.getBytes())).toString();
}
public String decrypt(String text) throws Exception {
SecretKeySpec spec = getKeySpec();
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, spec);
BASE64Decoder dec = new BASE64Decoder();
return new String(cipher.doFinal(dec.decodeBuffer(text)));
}
public static void main(String[] args) throws Exception {
String mode = "encrypt";
String text = "!mpluse0218";
String encText = "";
String decText = "";
AES256 aes = new AES256();
encText=aes.encrypt(text);
System.out.println("5ClhQFro0UAI+LrZkilamw==");
System.out.println("enc::"+encText);
decText = aes.decrypt(encText);
System.out.println("dec::"+decText);
}
}
import sun.misc.BASE64Decoder;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.io.*;
import java.security.NoSuchAlgorithmException;
public class AES256 {
public static SecretKeySpec getKeySpec() throws IOException, NoSuchAlgorithmException {
byte[] bytes = new byte[32];
SecretKey key = null;
SecretKeySpec spec = null;
/*
File f = new File("aes_key");
if (f.exists()) {
new FileInputStream(f).read(bytes);
} else {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(256);
key = kgen.generateKey();
bytes1 = key.getEncoded();
new FileOutputStream(f).write(bytes1);
}
*/
String keyStr="암호화된 대칭키";
bytes = Base64Utils.base64Decode(keyStr);
spec = new SecretKeySpec(bytes,"AES");
return spec;
}
public String encrypt(String text) throws Exception {
SecretKeySpec spec = getKeySpec();
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, spec);
BASE64Encoder enc = new BASE64Encoder();
return enc.encode(cipher.doFinal(text.getBytes())).toString();
}
public String decrypt(String text) throws Exception {
SecretKeySpec spec = getKeySpec();
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, spec);
BASE64Decoder dec = new BASE64Decoder();
return new String(cipher.doFinal(dec.decodeBuffer(text)));
}
public static void main(String[] args) throws Exception {
String mode = "encrypt";
String text = "!mpluse0218";
String encText = "";
String decText = "";
AES256 aes = new AES256();
encText=aes.encrypt(text);
System.out.println("5ClhQFro0UAI+LrZkilamw==");
System.out.println("enc::"+encText);
decText = aes.decrypt(encText);
System.out.println("dec::"+decText);
}
}
SHA512 알고리즘
http://www.docjar.com/html/api/gnu/java/security/hash/Sha512.java.html
http://blog.fethilale.com/sha512-hashing-on-java/
http://blog.fethilale.com/sha512-hashing-on-java/
JAVA MessageDigest Class 활용한 방법
http://java.sun.com/j2se/1.4.2/docs/api/java/security/MessageDigest.html (JavaTM 2 Platform Std. Ed. v1.4.2)
This MessageDigest class provides applications the functionality of a message digest algorithm, such as MD5 or SHA. Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.
If you want to hash password with SHA256, you can change the line:
to
For others:
'Development' 카테고리의 다른 글
SYNTAX|SyntaxHighlighter (0) | 2010.08.16 |
---|---|
보안|개인정보 DB 암호화 관리 안내서 (0) | 2010.08.10 |
JavaScript|자바스크립 관련 사이트 (0) | 2010.07.21 |
PROC|오라클 프로씨(Pro *C/*C++ ) (0) | 2010.07.16 |
C++|C++ IDE (Code::Blocks, Dev-C++,....) (0) | 2010.07.08 |
Comments