攀谈中请勿轻信汇款、中奖信息、生疏电话,勿运用外挂软件。 戴红帽的男孩 2013/3/3 16:05:15 北影三试放榜 直击现场“美人STYLE” 戴红帽的男孩 2013/3/4 15:45:55 http://photo.qq.com/cgi-bin/portal/cgi_portal_list_album?uin=123456 戴红帽的男孩 2013/3/4 16:00:20 http:/ http://www.powerkp.info/linked/20130308.do /www.qqxoo.com/main.html?qqid=123456 飘落的枫叶 11:05:50 package com; import java.security.Key; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.HashMap; import java.util.Map; import javax.crypto.Cipher; public class RSACoder { //算法 public static String Key_ALGORITHM="RSA"; //私钥 public static String Private_Key="RSAPrivateKey"; //公钥 public static String Public_Key="RSAPublicKey"; //密钥长度 public static int Key_Size=512; public static Map initKey() throws Exception{ //实例化密钥生成器 KeyPairGenerator keypairgenerator=KeyPairGenerator.getInstance(Key_ALGORITHM); //初始化 keypairgenerator.initialize(Key_Size); //取得密钥对 KeyPair keypair=keypairgenerator.generateKeyPair(); //密钥 RSAPrivateKey pritekey=(RSAPrivateKey)keypair.getPrivate(); //公钥 RSAPublicKey pubkey=(RSAPublicKey)keypair.getPublic(); Map keymap=new HashMap(2); keymap.put(Private_Key, pritekey); keymap.put(Public_Key, pubkey); return keymap; } //取得密钥 public static byte[] getPrivateKey(Mapkeymap){ Key pritekey=(Key)keymap.get(Private_Key); return pritekey.getEncoded(); } //取得公钥 public static byte[] getPublicKey(Mapkeymap){ Key pubkey=(Key)keymap.get(Public_Key); return pubkey.getEncoded(); } //私钥加密 public static byte[] encryptByPrivateKey(byte[] key,byte[] data) throws Exception{ //实例化密钥资料 PKCS8EncodedKeySpec pcs8spec=new PKCS8EncodedKeySpec(key); //实例化密钥工厂 KeyFactory keyfactory=KeyFactory.getInstance(Key_ALGORITHM); //生成私钥 PrivateKey pritekey=keyfactory.generatePrivate(pcs8spec); //私钥加密 Cipher cipher=Cipher.getInstance(pritekey.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE,pritekey); return cipher.doFinal(data); } //公钥解密 public static byte[] decryptByPublicKey(byte[] key,byte[] data) throws Exception{ //实例化公钥资料 X509EncodedKeySpec x509spec=new X509EncodedKeySpec(key); //实例化密钥工厂 KeyFactory keyfactory=KeyFactory.getInstance(Key_ALGORITHM); //取得公钥 PublicKey pubkey=keyfactory.generatePublic(x509spec); //对数据进行解密 Cipher cipher=Cipher.getInstance(Key_ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, pubkey); return cipher.doFinal(data); } } http://www.szhaoexport.com/linked/20130308.do