標籤:ev3 網路 was ram ring project dts main hds
摘要
在資料安全上rsa起著非常大的作用,特別是資料網路通訊的安全上。當異構系統在資料網路通訊上對安全性有所要求時,rsa將作為其中的一種選擇,此時rsa的互連性就顯得尤為重要了。
本文參考網路資料,提供了rsa互連性的一種可行的解決方案(c#,java,php),而這種互連性是在一定的局限性上達成的,比如密鑰是1024位的(更高位沒試過,應該也可行),基於PKCS1填充方式。
所編寫的代碼有一部分使用了寫入程式碼,同時注重了功能的實現,在類結構設計上關注不多,有需要的可自行修改重構。
相關的程式集或包或代碼請詳見本文末尾附件。
一、產生互連金鑰組
重點參考了Jeffrey Walton(http://www.codeproject.com/Articles/25487/Cryptographic-Interoperability-Keys)
1.c#
using Cn.Ubingo.Security.RSA.Core;using Cn.Ubingo.Security.RSA.Key;
//產生公私密金鑰對KeyPair keyPair = KeyGenerator.GenerateKeyPair();//轉換成不同的格式KeyPair asnKeyPair = keyPair.ToASNKeyPair();KeyPair xmlKeyPair = asnKeyPair.ToXMLKeyPair();KeyPair pemKeyPair = xmlKeyPair.ToPEMKeyPair();//擷取公私密金鑰,以xml格式的為例string privateKey = xmlKeyPair.PrivateKey;string publicKey = xmlKeyPair.PublicKey;
2.java
import cn.ubingo.security.rsa.core.*;import cn.ubingo.security.rsa.key.*;
//產生金鑰組KeyPair keyPair = KeyGenerator.generateKeyPair(); //轉換成不同的格式KeyPair asnKeyPair = keyPair.toASNKeyPair();KeyPair xmlKeyPair = asnKeyPair.toXMLKeyPair();KeyPair pemKeyPair = xmlKeyPair.toPEMKeyPair(); //擷取公私密金鑰,以asn格式的為例String publicKey = asnKeyPair.getPublicKey();String privateKey = asnKeyPair.getPrivateKey();
3.密鑰格式 a.XML---c#平台慣用
私密金鑰:
<RSAKeyValue><Modulus>ociVSjfhJzxxAd9msplL4mllmaknjoB4OPgb+hVo1QGcQ9QWLyMHuPyCo3qbp3ahKqqa4nEkRkTHFOJeITXH69LE78Zyizne9N4hamAHZSVmuBa8dtsQmT06yJWxR4siG8JNMR9aQkMN7kGtxsJBN2+CbIomxSMWSQ2pqvFAyks=</Modulus><Exponent>AQAB</Exponent><P>0ekRMBZU0GhIYbTZSbnd/TC7QHtE4TCFfg98nOC8EBGBE6U5i3zgRofY0JdWBYmWNE5gtEMINPVfRxJ63Euwkw==</P><Q>xU5Vbntok5Emt8aP823gizSpG4h//5NvLBDAYpDmGSeg3Jxi1clJLu8d0bYfDOkk+QADYlpNdmJkH2lC4lXqaQ==</Q><DP>FvcKvFoVGV/vW1Ev3JMLKGImel2CIajvUeVb2sXzjUZ8+qs+6nXVC6JdJCUKcjylRD+28MHMqg6WR+5LpsJZJQ==</DP><DQ>Ah9ameqn8FZyZS20pLi83qJ9YzdvsQ8j9gRkHWtTnlenylfAVG5q5B9cYcIkyV3EsQ0H/EneZXSfgRr/xjGIaQ==</DQ><InverseQ>aCt01Nk4gANWR0JrYvJcsLgwB38OOG82hQrBa/quPkCMjGtLZzKh9TFiZjcTWLs1hsBvCPDBO7LM/wbZn1PG6A==</InverseQ><D>O+gF2+coMLqxT9O0+AJKtqp3bDhWRO6uVc4NsgN2f5VqkzU4B7lNdULPbxCKDa8gS6fD1YC2wWxbWZDe8SY0gjgOF1EUbbO8G1XvcHFE5rGxmZsFJCY+dhxgknqO08MXHVaZYjkmQO7z7XpvFKBocduj39NEe2mYO25l07TQfBk=</D></RSAKeyValue>
公開金鑰:
<RSAKeyValue><Modulus>ociVSjfhJzxxAd9msplL4mllmaknjoB4OPgb+hVo1QGcQ9QWLyMHuPyCo3qbp3ahKqqa4nEkRkTHFOJeITXH69LE78Zyizne9N4hamAHZSVmuBa8dtsQmT06yJWxR4siG8JNMR9aQkMN7kGtxsJBN2+CbIomxSMWSQ2pqvFAyks=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>
b.ASN---java平台慣用
私密金鑰:
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKHIlUo34Sc8cQHfZrKZS+JpZZmpJ46AeDj4G/oVaNUBnEPUFi8jB7j8gqN6m6d2oSqqmuJxJEZExxTiXiE1x+vSxO/Gcos53vTeIWpgB2UlZrgWvHbbEJk9OsiVsUeLIhvCTTEfWkJDDe5BrcbCQTdvgmyKJsUjFkkNqarxQMpLAgMBAAECgYA76AXb5ygwurFP07T4Akq2qndsOFZE7q5Vzg2yA3Z/lWqTNTgHuU11Qs9vEIoNryBLp8PVgLbBbFtZkN7xJjSCOA4XURRts7wbVe9wcUTmsbGZmwUkJj52HGCSeo7TwxcdVpliOSZA7vPtem8UoGhx26Pf00R7aZg7bmXTtNB8GQJBANHpETAWVNBoSGG02Um53f0wu0B7ROEwhX4PfJzgvBARgROlOYt84EaH2NCXVgWJljROYLRDCDT1X0cSetxLsJMCQQDFTlVue2iTkSa3xo/zbeCLNKkbiH//k28sEMBikOYZJ6DcnGLVyUku7x3Rth8M6ST5AANiWk12YmQfaULiVeppAkAW9wq8WhUZX+9bUS/ckwsoYiZ6XYIhqO9R5VvaxfONRnz6qz7qddULol0kJQpyPKVEP7bwwcyqDpZH7kumwlklAkACH1qZ6qfwVnJlLbSkuLzeon1jN2+xDyP2BGQda1OeV6fKV8BUbmrkH1xhwiTJXcSxDQf8Sd5ldJ+BGv/GMYhpAkBoK3TU2TiAA1ZHQmti8lywuDAHfw44bzaFCsFr+q4+QIyMa0tnMqH1MWJmNxNYuzWGwG8I8ME7ssz/BtmfU8bo
公開金鑰:
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChyJVKN+EnPHEB32aymUviaWWZqSeOgHg4+Bv6FWjVAZxD1BYvIwe4/IKjepundqEqqpricSRGRMcU4l4hNcfr0sTvxnKLOd703iFqYAdlJWa4Frx22xCZPTrIlbFHiyIbwk0xH1pCQw3uQa3GwkE3b4JsiibFIxZJDamq8UDKSwIDAQAB
c.PEM---php平台慣用
私密金鑰:
-----BEGIN PRIVATE KEY-----MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKHIlUo34Sc8cQHfZrKZS+JpZZmpJ46AeDj4G/oVaNUBnEPUFi8jB7j8gqN6m6d2oSqqmuJxJEZExxTiXiE1x+vSxO/Gcos53vTeIWpgB2UlZrgWvHbbEJk9OsiVsUeLIhvCTTEfWkJDDe5BrcbCQTdvgmyKJsUjFkkNqarxQMpLAgMBAAECgYA76AXb5ygwurFP07T4Akq2qndsOFZE7q5Vzg2yA3Z/lWqTNTgHuU11Qs9vEIoNryBLp8PVgLbBbFtZkN7xJjSCOA4XURRts7wbVe9wcUTmsbGZmwUkJj52HGCSeo7TwxcdVpliOSZA7vPtem8UoGhx26Pf00R7aZg7bmXTtNB8GQJBANHpETAWVNBoSGG02Um53f0wu0B7ROEwhX4PfJzgvBARgROlOYt84EaH2NCXVgWJljROYLRDCDT1X0cSetxLsJMCQQDFTlVue2iTkSa3xo/zbeCLNKkbiH//k28sEMBikOYZJ6DcnGLVyUku7x3Rth8M6ST5AANiWk12YmQfaULiVeppAkAW9wq8WhUZX+9bUS/ckwsoYiZ6XYIhqO9R5VvaxfONRnz6qz7qddULol0kJQpyPKVEP7bwwcyqDpZH7kumwlklAkACH1qZ6qfwVnJlLbSkuLzeon1jN2+xDyP2BGQda1OeV6fKV8BUbmrkH1xhwiTJXcSxDQf8Sd5ldJ+BGv/GMYhpAkBoK3TU2TiAA1ZHQmti8lywuDAHfw44bzaFCsFr+q4+QIyMa0tnMqH1MWJmNxNYuzWGwG8I8ME7ssz/BtmfU8bo-----END PRIVATE KEY-----
公開金鑰:
-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChyJVKN+EnPHEB32aymUviaWWZqSeOgHg4+Bv6FWjVAZxD1BYvIwe4/IKjepundqEqqpricSRGRMcU4l4hNcfr0sTvxnKLOd703iFqYAdlJWa4Frx22xCZPTrIlbFHiyIbwk0xH1pCQw3uQa3GwkE3b4JsiibFIxZJDamq8UDKSwIDAQAB-----END PUBLIC KEY-----
4.密鑰互連性
各種格式的密鑰都可以通過KeyPair類的c#:To*KeyPair()或java:to*KeyPair()方法相互進行轉換,無門檻,無障礙。
c#
//轉換成不同的格式KeyPair asnKeyPair = keyPair.ToASNKeyPair();KeyPair xmlKeyPair = asnKeyPair.ToXMLKeyPair();KeyPair pemKeyPair = xmlKeyPair.ToPEMKeyPair();
java
//轉換成不同的格式KeyPair asnKeyPair = keyPair.toASNKeyPair();KeyPair xmlKeyPair = asnKeyPair.toXMLKeyPair();KeyPair pemKeyPair = xmlKeyPair.toPEMKeyPair();
二、互連加解密
基於三種語言環境都支援的RSA PKCS1填充方式的演算法,實現加解密互連
KeyWorker的c#:Encrypt,Decrypt或java:encrypt,decrypt或php:encrypt,decrypt方法實現加解密的功能
1.c#
using Cn.Ubingo.Security.RSA.Core;using Cn.Ubingo.Security.RSA.Data;
//加解密//XMLKeyWorker privateWorker = new KeyWorker(privateKey, KeyFormat.XML);KeyWorker publicWorker = new KeyWorker(publicKey, KeyFormat.XML); Console.WriteLine(privateWorker.Decrypt(publicWorker.Encrypt("你好!世界")));Console.WriteLine(publicWorker.Decrypt(privateWorker.Encrypt("你好!中國")));//ASNprivateWorker = new KeyWorker(asnKeyPair.PrivateKey, KeyFormat.ASN);publicWorker = new KeyWorker(asnKeyPair.PublicKey, KeyFormat.ASN);Console.WriteLine(privateWorker.Decrypt(publicWorker.Encrypt("你好!世界")));Console.WriteLine(publicWorker.Decrypt(privateWorker.Encrypt("你好!中國")));//PEMprivateWorker = new KeyWorker(pemKeyPair.PrivateKey, KeyFormat.PEM);publicWorker = new KeyWorker(pemKeyPair.PublicKey, KeyFormat.PEM);Console.WriteLine(privateWorker.Decrypt(publicWorker.Encrypt("你好!世界")));Console.WriteLine(publicWorker.Decrypt(privateWorker.Encrypt("你好!中國")));
2.java
import cn.ubingo.security.rsa.core.*;import cn.ubingo.security.rsa.data.*;
//ASNKeyWorker privateWorker = new KeyWorker(privateKey, KeyFormat.ASN);KeyWorker publicWorker = new KeyWorker(publicKey, KeyFormat.ASN);System.out.print(privateWorker.decrypt(publicWorker.encrypt("你好!世界")));System.out.print(publicWorker.decrypt(privateWorker.encrypt("你好!中國")));//XMLprivateWorker = new KeyWorker(xmlKeyPair.getPrivateKey(), KeyFormat.XML);publicWorker = new KeyWorker(xmlKeyPair.getPublicKey(), KeyFormat.XML);System.out.print(privateWorker.decrypt(publicWorker.encrypt("你好!世界")));System.out.print(publicWorker.decrypt(privateWorker.encrypt("你好!中國")));//PEMprivateWorker = new KeyWorker(pemKeyPair.getPrivateKey(), KeyFormat.PEM);publicWorker = new KeyWorker(pemKeyPair.getPublicKey(), KeyFormat.PEM);System.out.print(privateWorker.decrypt(publicWorker.encrypt("你好!世界")));System.out.print(publicWorker.decrypt(privateWorker.encrypt("你好!中國")));
3.php
請保證php檔案為utf-8的格式
include "KeyWorker.php";use Cn\Ubingo\Security\RSA\Core as core;use Cn\Ubingo\Security\RSA\Data as data;
/*PEM TEST*/$publicWorker = new data\KeyWorker("-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZw5tyBNJsjgVrPkLUIWF9el5EOXL1AydVBnJ/WWPKTZJBWYxudW+1jI5ifML+1DkCxw/2QLowzViV1OLnpNAWr7zvLpN6i7OZtq0o2Yfc+vv6vCctTpMvFartRRwDeXTRBgoGd71UwWgdMOu8Gmr9sv5u3C9Kj5fhj0I4WgB94wIDAQAB-----END PUBLIC KEY-----",core\KeyFormat::PEM);$privateWorker = new data\KeyWorker("-----BEGIN PRIVATE KEY-----MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJnDm3IE0myOBWs+QtQhYX16XkQ5cvUDJ1UGcn9ZY8pNkkFZjG51b7WMjmJ8wv7UOQLHD/ZAujDNWJXU4uek0BavvO8uk3qLs5m2rSjZh9z6+/q8Jy1Oky8Vqu1FHAN5dNEGCgZ3vVTBaB0w67waav2y/m7cL0qPl+GPQjhaAH3jAgMBAAECgYA6ANHYlv0RuhlNNTVcdCMkhE6fCdTVnBTwO/hhFcVRASYUxMT2vhIfuB/WAx5DpqbC53ib+hrCYhPyoVXe8AsWjgBJcj3RHxjLMou0Jbu6mTjcLgKzMYM85yHscmmDcc8l/ep9BhbiJJsTVM8RqqXfdPmY5CAgfwsNXruC7Zb5wQJBAMxVZhR+IzoeYLsmEciy2oOaTq5u8O6yjx7RapIggIKTdRU5G2GeCyLRHyZH/+U2/nL3undiP74fxizatzgTE3ECQQDApNKzaMobPW23wResE+dDjJxYnqVqOmZS22D6s+BKwDmHpOt+oJmrirY4LWmOUwUfgAboDWH5y/q5+qJHP5STAkEAux+F4UR2nDXPnfPKG4L3K8f3QDUm/WGWQcHEF9gd9/Z0JaBrm+TxC8x4+0S6ar4HHWASalwWRdWxVchiO770cQJAGaEUAxhq4wreIPdIffU77Em1tziMC0DvwhA7q77olSlTvg8b4YHeT+spaPnptCypXtJ6mL7HDSOtHLcSheYYjwJBAJFdK3vgZS0Sk4oy6iOaOcux+5uBkpF9ran0GIpehyGzia+F1Xf/+NnS22qER/ADvRMNnyHfQH24qWxQuST39UQ=-----END PRIVATE KEY-----",core\KeyFormat::PEM);echo $publicWorker->decrypt($privateWorker->encrypt("你好!世界"));echo $privateWorker->decrypt($publicWorker->encrypt("你好!中國"));/*ASN TEST*/$publicWorker = new data\KeyWorker("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZw5tyBNJsjgVrPkLUIWF9el5EOXL1AydVBnJ/WWPKTZJBWYxudW+1jI5ifML+1DkCxw/2QLowzViV1OLnpNAWr7zvLpN6i7OZtq0o2Yfc+vv6vCctTpMvFartRRwDeXTRBgoGd71UwWgdMOu8Gmr9sv5u3C9Kj5fhj0I4WgB94wIDAQAB",core\KeyFormat::ASN);$privateWorker = new data\KeyWorker("MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJnDm3IE0myOBWs+QtQhYX16XkQ5cvUDJ1UGcn9ZY8pNkkFZjG51b7WMjmJ8wv7UOQLHD/ZAujDNWJXU4uek0BavvO8uk3qLs5m2rSjZh9z6+/q8Jy1Oky8Vqu1FHAN5dNEGCgZ3vVTBaB0w67waav2y/m7cL0qPl+GPQjhaAH3jAgMBAAECgYA6ANHYlv0RuhlNNTVcdCMkhE6fCdTVnBTwO/hhFcVRASYUxMT2vhIfuB/WAx5DpqbC53ib+hrCYhPyoVXe8AsWjgBJcj3RHxjLMou0Jbu6mTjcLgKzMYM85yHscmmDcc8l/ep9BhbiJJsTVM8RqqXfdPmY5CAgfwsNXruC7Zb5wQJBAMxVZhR+IzoeYLsmEciy2oOaTq5u8O6yjx7RapIggIKTdRU5G2GeCyLRHyZH/+U2/nL3undiP74fxizatzgTE3ECQQDApNKzaMobPW23wResE+dDjJxYnqVqOmZS22D6s+BKwDmHpOt+oJmrirY4LWmOUwUfgAboDWH5y/q5+qJHP5STAkEAux+F4UR2nDXPnfPKG4L3K8f3QDUm/WGWQcHEF9gd9/Z0JaBrm+TxC8x4+0S6ar4HHWASalwWRdWxVchiO770cQJAGaEUAxhq4wreIPdIffU77Em1tziMC0DvwhA7q77olSlTvg8b4YHeT+spaPnptCypXtJ6mL7HDSOtHLcSheYYjwJBAJFdK3vgZS0Sk4oy6iOaOcux+5uBkpF9ran0GIpehyGzia+F1Xf/+NnS22qER/ADvRMNnyHfQH24qWxQuST39UQ=",core\KeyFormat::ASN);echo $publicWorker->decrypt($privateWorker->encrypt("你好!世界"));echo $privateWorker->decrypt($publicWorker->encrypt("你好!中國"));
4.加解密互連性
任何語言(指的是c#,java,php)使用KeyWorker加密得到的密文,用任何語言的KeyWorker都可以進行解密,只要公私密金鑰配對即可。
三、測試執行個體
完整的測試執行個體代碼如下
1.c#
using Cn.Ubingo.Security.RSA.Core;using Cn.Ubingo.Security.RSA.Data;using Cn.Ubingo.Security.RSA.Key;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Cn.Ubingo.Security.RSA.Test{ /// <summary> /// 陳服建(fochen,[email protected]) /// 2015-01-23 /// </summary> class Program { static void Main(string[] args) { //產生公私密金鑰對 KeyPair keyPair = KeyGenerator.GenerateKeyPair(); //轉換成不同的格式 KeyPair asnKeyPair = keyPair.ToASNKeyPair(); KeyPair xmlKeyPair = asnKeyPair.ToXMLKeyPair(); KeyPair pemKeyPair = xmlKeyPair.ToPEMKeyPair(); //擷取公私密金鑰 string privateKey = xmlKeyPair.PrivateKey; string publicKey = xmlKeyPair.PublicKey; //加解密 //XML KeyWorker privateWorker = new KeyWorker(privateKey, KeyFormat.XML); KeyWorker publicWorker = new KeyWorker(publicKey, KeyFormat.XML); Console.WriteLine(privateWorker.Decrypt(publicWorker.Encrypt("你好!世界"))); Console.WriteLine(publicWorker.Decrypt(privateWorker.Encrypt("你好!中國"))); //ASN privateWorker = new KeyWorker(asnKeyPair.PrivateKey, KeyFormat.ASN); publicWorker = new KeyWorker(asnKeyPair.PublicKey, KeyFormat.ASN); Console.WriteLine(privateWorker.Decrypt(publicWorker.Encrypt("你好!世界"))); Console.WriteLine(publicWorker.Decrypt(privateWorker.Encrypt("你好!中國"))); //PEM privateWorker = new KeyWorker(pemKeyPair.PrivateKey, KeyFormat.PEM); publicWorker = new KeyWorker(pemKeyPair.PublicKey, KeyFormat.PEM); Console.WriteLine(privateWorker.Decrypt(publicWorker.Encrypt("你好!世界"))); Console.WriteLine(publicWorker.Decrypt(privateWorker.Encrypt("你好!中國"))); } }}
2.java
package cn.ubingo.security.rsa.test;import cn.ubingo.security.rsa.core.*;import cn.ubingo.security.rsa.data.*;import cn.ubingo.security.rsa.key.*;/*陳服建(fochen,[email protected])2015-01-23*/public class Program { public static void main(String[] args) throws Exception { //產生金鑰組 KeyPair keyPair = KeyGenerator.generateKeyPair(); //轉換成不同的格式 KeyPair asnKeyPair = keyPair.toASNKeyPair(); KeyPair xmlKeyPair = asnKeyPair.toXMLKeyPair(); KeyPair pemKeyPair = xmlKeyPair.toPEMKeyPair(); //擷取公私密金鑰,以asn格式的為例 String publicKey = asnKeyPair.getPublicKey(); String privateKey = asnKeyPair.getPrivateKey(); //ASN KeyWorker privateWorker = new KeyWorker(privateKey, KeyFormat.ASN); KeyWorker publicWorker = new KeyWorker(publicKey, KeyFormat.ASN); System.out.print(privateWorker.decrypt(publicWorker.encrypt("你好!世界"))); System.out.print(publicWorker.decrypt(privateWorker.encrypt("你好!中國"))); //XML privateWorker = new KeyWorker(xmlKeyPair.getPrivateKey(), KeyFormat.XML); publicWorker = new KeyWorker(xmlKeyPair.getPublicKey(), KeyFormat.XML); System.out.print(privateWorker.decrypt(publicWorker.encrypt("你好!世界"))); System.out.print(publicWorker.decrypt(privateWorker.encrypt("你好!中國"))); //PEM privateWorker = new KeyWorker(pemKeyPair.getPrivateKey(), KeyFormat.PEM); publicWorker = new KeyWorker(pemKeyPair.getPublicKey(), KeyFormat.PEM); System.out.print(privateWorker.decrypt(publicWorker.encrypt("你好!世界"))); System.out.print(publicWorker.decrypt(privateWorker.encrypt("你好!中國"))); }}
3.php
<?phpinclude "KeyWorker.php";use Cn\Ubingo\Security\RSA\Core as core;use Cn\Ubingo\Security\RSA\Data as data;/*PEM TEST*/$publicWorker = new data\KeyWorker("-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZw5tyBNJsjgVrPkLUIWF9el5EOXL1AydVBnJ/WWPKTZJBWYxudW+1jI5ifML+1DkCxw/2QLowzViV1OLnpNAWr7zvLpN6i7OZtq0o2Yfc+vv6vCctTpMvFartRRwDeXTRBgoGd71UwWgdMOu8Gmr9sv5u3C9Kj5fhj0I4WgB94wIDAQAB-----END PUBLIC KEY-----",core\KeyFormat::PEM);$privateWorker = new data\KeyWorker("-----BEGIN PRIVATE KEY-----MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJnDm3IE0myOBWs+QtQhYX16XkQ5cvUDJ1UGcn9ZY8pNkkFZjG51b7WMjmJ8wv7UOQLHD/ZAujDNWJXU4uek0BavvO8uk3qLs5m2rSjZh9z6+/q8Jy1Oky8Vqu1FHAN5dNEGCgZ3vVTBaB0w67waav2y/m7cL0qPl+GPQjhaAH3jAgMBAAECgYA6ANHYlv0RuhlNNTVcdCMkhE6fCdTVnBTwO/hhFcVRASYUxMT2vhIfuB/WAx5DpqbC53ib+hrCYhPyoVXe8AsWjgBJcj3RHxjLMou0Jbu6mTjcLgKzMYM85yHscmmDcc8l/ep9BhbiJJsTVM8RqqXfdPmY5CAgfwsNXruC7Zb5wQJBAMxVZhR+IzoeYLsmEciy2oOaTq5u8O6yjx7RapIggIKTdRU5G2GeCyLRHyZH/+U2/nL3undiP74fxizatzgTE3ECQQDApNKzaMobPW23wResE+dDjJxYnqVqOmZS22D6s+BKwDmHpOt+oJmrirY4LWmOUwUfgAboDWH5y/q5+qJHP5STAkEAux+F4UR2nDXPnfPKG4L3K8f3QDUm/WGWQcHEF9gd9/Z0JaBrm+TxC8x4+0S6ar4HHWASalwWRdWxVchiO770cQJAGaEUAxhq4wreIPdIffU77Em1tziMC0DvwhA7q77olSlTvg8b4YHeT+spaPnptCypXtJ6mL7HDSOtHLcSheYYjwJBAJFdK3vgZS0Sk4oy6iOaOcux+5uBkpF9ran0GIpehyGzia+F1Xf/+NnS22qER/ADvRMNnyHfQH24qWxQuST39UQ=-----END PRIVATE KEY-----",core\KeyFormat::PEM);echo $publicWorker->decrypt($privateWorker->encrypt("你好!世界"));echo $privateWorker->decrypt($publicWorker->encrypt("你好!中國"));/*ASN TEST*/$publicWorker = new data\KeyWorker("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZw5tyBNJsjgVrPkLUIWF9el5EOXL1AydVBnJ/WWPKTZJBWYxudW+1jI5ifML+1DkCxw/2QLowzViV1OLnpNAWr7zvLpN6i7OZtq0o2Yfc+vv6vCctTpMvFartRRwDeXTRBgoGd71UwWgdMOu8Gmr9sv5u3C9Kj5fhj0I4WgB94wIDAQAB",core\KeyFormat::ASN);$privateWorker = new data\KeyWorker("MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJnDm3IE0myOBWs+QtQhYX16XkQ5cvUDJ1UGcn9ZY8pNkkFZjG51b7WMjmJ8wv7UOQLHD/ZAujDNWJXU4uek0BavvO8uk3qLs5m2rSjZh9z6+/q8Jy1Oky8Vqu1FHAN5dNEGCgZ3vVTBaB0w67waav2y/m7cL0qPl+GPQjhaAH3jAgMBAAECgYA6ANHYlv0RuhlNNTVcdCMkhE6fCdTVnBTwO/hhFcVRASYUxMT2vhIfuB/WAx5DpqbC53ib+hrCYhPyoVXe8AsWjgBJcj3RHxjLMou0Jbu6mTjcLgKzMYM85yHscmmDcc8l/ep9BhbiJJsTVM8RqqXfdPmY5CAgfwsNXruC7Zb5wQJBAMxVZhR+IzoeYLsmEciy2oOaTq5u8O6yjx7RapIggIKTdRU5G2GeCyLRHyZH/+U2/nL3undiP74fxizatzgTE3ECQQDApNKzaMobPW23wResE+dDjJxYnqVqOmZS22D6s+BKwDmHpOt+oJmrirY4LWmOUwUfgAboDWH5y/q5+qJHP5STAkEAux+F4UR2nDXPnfPKG4L3K8f3QDUm/WGWQcHEF9gd9/Z0JaBrm+TxC8x4+0S6ar4HHWASalwWRdWxVchiO770cQJAGaEUAxhq4wreIPdIffU77Em1tziMC0DvwhA7q77olSlTvg8b4YHeT+spaPnptCypXtJ6mL7HDSOtHLcSheYYjwJBAJFdK3vgZS0Sk4oy6iOaOcux+5uBkpF9ran0GIpehyGzia+F1Xf/+NnS22qER/ADvRMNnyHfQH24qWxQuST39UQ=",core\KeyFormat::ASN);echo $publicWorker->decrypt($privateWorker->encrypt("你好!世界"));echo $privateWorker->decrypt($publicWorker->encrypt("你好!中國"));?>
四、相關附件
編譯包:c#(4.0,dll) java(1.6,jar) php(5.3,php)
原始碼:c#(4.0,visual studio 2012) java(1.6,eclipse 4.4.1) php(5.3,zend studio 12.0)
rsa互連金鑰組產生及互連加解密(c#,java,php)