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++ で復?する方法

·미리보기 | 소스복사·
  1. import java.io.File;   
  2. import java.io.FileOutputStream;   
  3. import java.io.FileInputStream;   
  4. import java.security.KeyFactory;   
  5. import java.security.Key;   
  6. import java.security.Security;   
  7. import java.security.spec.PKCS8EncodedKeySpec;   
  8. import java.security.spec.X509EncodedKeySpec;   
  9. import javax.crypto.Cipher;   
  10. import cryptix.jce.provider.CryptixCrypto;   
  11.   
  12. /*  
  13.  * encrypt stuff with RSA (cryptix)  
  14.  *  
  15.  * javac -classpath .:cryptix-jce-api.jar:cryptix-jce-provider.jar C.java  
  16.  * java -classpath .:cryptix-jce-api.jar:cryptix-jce-provider.jar C  
  17.  */  
  18. public class C {   
  19.   public static void main(String[] args) throws Exception {   
  20.     File f;   
  21.     FileInputStream i;   
  22.     FileOutputStream o;   
  23.     Runtime r = Runtime.getRuntime();   
  24.     byte[] plain = "howdy!n".getBytes();   
  25.     Security.addProvider(new CryptixCrypto());   
  26.     /* generate keys */  
  27.     r.exec("openssl genrsa -out pri.pem").waitFor();   
  28.     r.exec("openssl rsa -in pri.pem -pubout -outform DER -out pub.der").waitFor();   
  29.     r.exec("openssl rsa -in pri.pem -outform DER -out pri-rsa.der").waitFor();   
  30.     r.exec("openssl pkcs8 -nocrypt -topk8 -inform DER -in pri-rsa.der -outform DER -out pri.der").waitFor();   
  31.     /* read in keys */  
  32.     f = new File("pub.der");   
  33.     byte[] pub_e = new byte[(int) f.length()];   
  34.     i = new FileInputStream(f);   
  35.     i.read(pub_e);   
  36.     i.close();   
  37.     f = new File("pri.der"); //(not used)   
  38.     byte[] pri_e = new byte[(int) f.length()];   
  39.     i = new FileInputStream(f);   
  40.     i.read(pri_e);   
  41.     i.close();   
  42.     KeyFactory kf = KeyFactory.getInstance("RSA");   
  43.     Key pub = kf.generatePublic(new X509EncodedKeySpec(pub_e));   
  44.     Key pri = kf.generatePrivate(new PKCS8EncodedKeySpec(pri_e));   
  45.     /* encrypt */  
  46.     Cipher c = Cipher.getInstance("RSA/ECB/PKCS#1");// provider="CryptixCrypto"   
  47.     c.init(Cipher.ENCRYPT_MODE, pub);   
  48.     o = new FileOutputStream("secret");   
  49.     o.write(c.doFinal(plain));   
  50.     o.close();   
  51.     /* decrypt */  
  52.     r.exec("openssl pkcs8 -inform DER -in pri -nocrypt -out pri.pem -outform PEM").waitFor();   
  53.     r.exec("openssl rsautl -inkey pri.pem -in secret -decrypt -out plain").waitFor();   
  54.     /* display */  
  55.     i = new FileInputStream("plain");   
  56.     int d;   
  57.     while ((d = i.read()) >= 0) {   
  58.       System.out.write(d);   
  59.     }   
  60.   }   
  61. }  

번호 제목 sitelink1 글쓴이 날짜 조회 수
공지 [계속 추가중] SBOM 용어 정의   황제낙엽 2025.04.10 52
공지 [계속 추가중] Keycloak 용어 및 설정 옵션 정의   황제낙엽 2024.02.02 631
25 blowfish 알고리즘 file http://www.schneier.com/blowfish.html  황제낙엽 2008.01.22 239
24 OpenSSL을 이용한 보안 통신 API의 설계 및 구현 file   황제낙엽 2007.10.01 193
23 Windows환경에서의 OpenSSL설치 file   황제낙엽 2007.09.28 145
22 OpenSSL Command-Line HOWTO   황제낙엽 2007.09.27 437
21 Certificate Server의 설치 와 Client인증 http://wiki.kldp.org/wiki.php/LinuxdocSgml/OpenSSL-KLDP  황제낙엽 2007.09.27 310
20 OpenSSL의 설치 및 운영 http://user.chol.com/~laday/solaris/openssl.html  황제낙엽 2007.09.27 200
19 OpenSSL 프로그래밍   황제낙엽 2007.09.27 1363
18 OpenSSL 을 통한 파일 암호화   황제낙엽 2007.09.27 361
17 OpenSSL 과 OpenSSH 소스 파일 (Language : C)   황제낙엽 2007.09.24 181
16 RSA 암호화 알고리즘을 구현한 C++ 예제 file http://labs.jong10.com/category/cryptology  황제낙엽 2007.09.17 1400
15 RSA암호화를 이용한 로그인 ID/패스워드 정보 관리 http://blog.dalsu.net/61  황제낙엽 2007.09.05 258
14 PHP와 OpenSSL http://www.ecoop.net/memo/2007-04-26-3.html  황제낙엽 2007.09.27 272
13 RSA 공개키 암호화 알고리즘 - PHP 구현[2] file   황제낙엽 2007.09.27 393
12 RSA 공개키 암호화 알고리즘 - PHP 구현[1] file   황제낙엽 2007.09.05 179
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