sitelink1 | |
---|---|
sitelink2 | |
sitelink3 | |
sitelink4 | |
extra_vars5 | |
extra_vars6 |
http://java-house.jp/ml/archive/j-h-b/051350.html
주의 사항 : 개인적으로도 검증하지 못한 예제이므로 충분히 검토후에 사용할 것
1. 대상환경
- 웹서버 : AIX WebSpehere어플리케이션서버 4.0
- 클라이언트 : WindowsNT VisualC++6.0
2. Java で暗?化してC++ で復?する方法
·미리보기 | 소스복사·
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.FileInputStream;
- import java.security.KeyFactory;
- import java.security.Key;
- import java.security.Security;
- import java.security.spec.PKCS8EncodedKeySpec;
- import java.security.spec.X509EncodedKeySpec;
- import javax.crypto.Cipher;
- import cryptix.jce.provider.CryptixCrypto;
- /*
- * encrypt stuff with RSA (cryptix)
- *
- * javac -classpath .:cryptix-jce-api.jar:cryptix-jce-provider.jar C.java
- * java -classpath .:cryptix-jce-api.jar:cryptix-jce-provider.jar C
- */
- public class C {
- public static void main(String[] args) throws Exception {
- File f;
- FileInputStream i;
- FileOutputStream o;
- Runtime r = Runtime.getRuntime();
- byte[] plain = "howdy!n".getBytes();
- Security.addProvider(new CryptixCrypto());
- /* generate keys */
- r.exec("openssl genrsa -out pri.pem").waitFor();
- r.exec("openssl rsa -in pri.pem -pubout -outform DER -out pub.der").waitFor();
- r.exec("openssl rsa -in pri.pem -outform DER -out pri-rsa.der").waitFor();
- r.exec("openssl pkcs8 -nocrypt -topk8 -inform DER -in pri-rsa.der -outform DER -out pri.der").waitFor();
- /* read in keys */
- f = new File("pub.der");
- byte[] pub_e = new byte[(int) f.length()];
- i = new FileInputStream(f);
- i.read(pub_e);
- i.close();
- f = new File("pri.der"); //(not used)
- byte[] pri_e = new byte[(int) f.length()];
- i = new FileInputStream(f);
- i.read(pri_e);
- i.close();
- KeyFactory kf = KeyFactory.getInstance("RSA");
- Key pub = kf.generatePublic(new X509EncodedKeySpec(pub_e));
- Key pri = kf.generatePrivate(new PKCS8EncodedKeySpec(pri_e));
- /* encrypt */
- Cipher c = Cipher.getInstance("RSA/ECB/PKCS#1");// provider="CryptixCrypto"
- c.init(Cipher.ENCRYPT_MODE, pub);
- o = new FileOutputStream("secret");
- o.write(c.doFinal(plain));
- o.close();
- /* decrypt */
- r.exec("openssl pkcs8 -inform DER -in pri -nocrypt -out pri.pem -outform PEM").waitFor();
- r.exec("openssl rsautl -inkey pri.pem -in secret -decrypt -out plain").waitFor();
- /* display */
- i = new FileInputStream("plain");
- int d;
- while ((d = i.read()) >= 0) {
- System.out.write(d);
- }
- }
- }
댓글 0
번호 | 제목 | sitelink1 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
공지 | [계속 추가중] SBOM 용어 정의 | 황제낙엽 | 2025.04.10 | 52 | |
공지 | [계속 추가중] Keycloak 용어 및 설정 옵션 정의 | 황제낙엽 | 2024.02.02 | 631 | |
13 | [Copilot] javax.crypto 패키지를 사용하여 암호화, 복호화 하는 방법 | 황제낙엽 | 2024.06.07 | 96 | |
12 | Apache Log4j 2 보안 업데이트 권고 | https://www.boho.or.kr/data/secNoticeVie...ence=36389 | 황제낙엽 | 2021.12.13 | 134 |
11 | OpenSSL사용방법 메모, RSA암호의 최대 사이즈, JCA/JCE가이드 | 황제낙엽 | 2007.09.27 | 173 | |
10 | Java Cryptography Extension (JCE) 개요 | 황제낙엽 | 2007.09.27 | 345 | |
» | Java에서 암호화하고 C++에서 복호화하는 방법 | 황제낙엽 | 2007.09.27 | 378 | |
8 | 비밀키를 Keytool에서 취급할 수 있는 형식으로 변환방법 | http://java-house.jp/ml/archive/j-h-b/051472.html | 황제낙엽 | 2007.09.27 | 229 |
7 | 공개키 암호화의 수학적 알고리즘과 자바 구현 | 황제낙엽 | 2007.09.22 | 207 | |
6 | RSA 암호화 알고리즘을 구현한 자바예제 (산술계산) | 황제낙엽 | 2007.09.17 | 326 | |
5 |
RSA 암호화 프로그램 예제 (BigInteger 이용)
![]() | 황제낙엽 | 2007.09.08 | 257 | |
4 | 해쉬를 이용한 패스워드 로그인 | 황제낙엽 | 2007.09.05 | 111 | |
3 |
Java 보안과 암호화 (개론)
![]() | 황제낙엽 | 2007.09.05 | 117 | |
2 | RSA 공개키 암호화 방식 (java.security, javax.crypto, au.net.aba.crypto.provider 패키지 이용) | 황제낙엽 | 2007.09.05 | 279 | |
1 | 자바 암호화 기법 - MD5를 이용한 해쉬키 생성 (Hash) | 황제낙엽 | 2007.09.01 | 316 |