java¼ÓÃܺÍÊý×ÖÇ©Ãû2 ˽Կ¼ÓÃÜ
½ü³õ²½½Ó´¥ÁËÏÂJava¼ÓÃܺÍÊý×ÖÇ©ÃûµÄÏà¹ØÄÚÈÝ£¬ÎÒѧϰµÄ¹ý³Ì´ó¸Å·ÖÎå²½£º
1£©ÏûÏ¢ÕªÒª
2£©Ë½Ô¿¼ÓÃÜ
3£©¹«Ô¿¼ÓÃÜ
4£©Êý×ÖÇ©Ãû
5) Êý×ÖÖ¤Êé
ÏÂÃæµÄ´úÂëÊǵڶþ²¿·Ö£ºË½Ô¿¼ÓÃÜ
Ï£ÍûÄÜΪ¸Õ¸Õ½Ó´¥Õâ¸öµÄÅóÓÑÃÇÊ¡µãÊÂ
package security;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import java.security.Key;
/**
* ´ËÀý×ÓÊǶÔÒ»¸ö×Ö·û´®ÐÅÏ¢£¬ÓÃÒ»¸ö˽Կ(key)¼ÓÃÜ£¬È»ºóÔÚÓøÃ˽Կ½âÃÜ£¬ÑéÖ¤ÊÇ·ñÒ»ÖÂ
* ˽Կ¼ÓÃÜ£¬ÊǶԳƼÓÃÜ
* ʹÓöԳÆËã·¨¡£±ÈÈ磺AÓÃÒ»¸öÃÜÔ¿¶ÔÒ»¸öÎļþ¼ÓÃÜ£¬¶øB¶ÁÈ¡Õâ¸öÎļþµÄ»°£¬ÔòÐèÒªºÍAÒ»ÑùµÄÃÜÔ¿£¬Ë«·½¹²ÏíÒ»
* ¸ö˽Կ£¨¶øÔÚweb»·¾³Ï£¬Ë½Ô¿ÔÚ´«µÝʱÈÝÒ×±»ÕìÌý£©
*
* ¸½£ºÖ÷Òª¶Ô³ÆËã·¨ÓУºDES£¨Êµ¼ÊÃÜÔ¿Ö»Óõ½56 룩
* AES£¨Ö§³ÖÈýÖÖÃÜÔ¿³¤¶È£º128¡¢192¡¢256룩£¬Í¨³£Ê×ÏÈ128룬ÆäËûµÄ»¹ÓÐDESedeµÈ
*/
public class PrivateKey {
public static void main(String[] args) throws Exception {
String before = "asdf";
byte[] plainText = before.getBytes("UTF8");
//1²½**********************************************************************
System.out.println("Start generate AES key.");
//µÃµ½Ò»¸öʹÓÃAESËã·¨µÄKeyGeneratorµÄʵÀý
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
//¶¨ÒåÃÜÔ¿³¤¶È128λ
keyGen.init(128);
//ͨ¹ýKeyGenerator²úÉúÒ»¸ökey£¨ÃÜÔ¿Ëã·¨¸Õ²ÅÒѶ¨Ò壬ΪAES£©
Key key = keyGen.generateKey();
System.out.println("Finish generating AES key."+key);
//2²½**********************************************************************
//»ñµÃÒ»¸ö˽Կ¼ÓÃÜÀàCipher£¬¶¨ÒåCipherµÄ»ù±¾ÐÅÏ¢£ºECBÊǼÓÃÜ·½Ê½£¬PKCS5PaddingÊÇÌî³ä·½·¨
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
// System.out.println("\n" + cipher.getProvider().getInfo());
//3²½**********************************************************************
//ʹÓÃ˽Կ¼ÓÃÜ
System.out.println("\nÓÃ˽Կ¼ÓÃÜ...");
//°Ñ¸Õ²ÅÉú³ÉµÄkeyµ±×÷²ÎÊý£¬³õʼ»¯Ê¹ÓøղŻñµÃµÄ˽Կ¼ÓÃÜÀ࣬Cipher.ENCRYPT_MODEÒâ˼ÊǼ
Ïà¹ØÎĵµ£º
JAVA¿ª·¢Õß×ȥµÄ20¸öÓ¢ÎÄÍøÕ¾
1.[http://www.javaalmanac.com] – Java¿ª·¢ÕßÄê¼øÒ»ÊéµÄÔÚÏß°æ±¾. ÒªÏë¿ìËٲ鵽ijÖÖJava¼¼ÇɵÄÓ÷¨¼°Ê¾Àý´úÂë, ÕâÊÇÒ»¸ö²»´íµÄÈ¥´¦.
2.[http://www.onjava.com] – O’ReillyµÄJavaÍøÕ¾. ÿÖܶ¼ÓÐÐÂÎÄÕÂ.
3.[http://java.sun.com] – ¹Ù·½µÄJava¿ª·¢ÕßÍøÕ¾ &ndash ......
1 ×÷ÓÃÓò
javaÖÐ×÷ÓÃÓòµÄ·¶Î§ÓÉ»¨À¨ºÅ±êʾ¡£
2¹ØÓÚstatic
À¬»øÊÕ¼¯Æ÷Ö»ÖªµÀËѼ¯ÄÇЩÓÐnewÔËËã·û·ÖÅäµÄÄڴ棬²»ÖªµÀÈçºÎÊÍ·ÅÌØÊâÄÚ´æ¡£
Èç¹ûÀ¬»øÊÕ¼¯Æ÷×¼±¸»ØÊÕ¶ÔÏóµÄÄڴ棬ËüÊ×Ïȵ÷ÓÃfinalize()£¬¶øÇÒÖ»ÓÐÔÚÏÂÒ»´ÎÀ¬»øËѼ¯¹ý³ÌÖУ¬²Å»áÕæÕý»ØÊÕ¶ÔÏóµÄÄÚ´æ¡£ËùÒÔ˵Èç¹ûʹÓÃ
final ......
Thread-Per-Message PatternµÄ²ÎÓëÕߣº
1. Client£¨Î¯ÍÐÈË£©²ÎÓëÕß
Client²ÎÓëÕß»á¶ÔHost²ÎÓëÕß·¢³öÇëÇó¡£Client²ÎÓëÕß²¢²»ÖªµÀHost²ÎÓëÕß»áÈçºÎʵÏÖÕâ¸öÇëÇó¡£
2. Host²ÎÓëÕß
µ±Host²ÎÓëÕß½ÓÊÕµ½Client²ÎÓëÕßµÄÇëÇóʱ£¬»á½¨Á¢ÐµÄÏ̲߳¢Æô¶¯Ëü¡£
Õâ¸öеÄÏ ......
JavaÓëÆäËûÓïÑԵĻ¥²Ù×÷ÐÔ ÊÕ²Ø
Ŀǰ£¬ÎÒÃÇÏîÄ¿ÖÐÐèÒªÓõ½°ÑJava³ÌÐòǶÈëµ½.Net³ÌÐòÖеļ¼Êõ£¬ÎÒÃÇ×îºóËù²ÉÓõļ¼ÊõÊÇCodemesh¹«Ë¾µÄJuggerNET¡£ÕâÖÖÀàËÆµÄ¼¼ÊõºÜ¶à£¬±È½ÏÖªÃûµÄÖ÷ÒªÓÐintrinsyc¹«Ë¾µÄJIntegraÒÔ¼°IBMµÄJava COM bridge¡£
ÏîÄ¿½øÐе½ÏÖÔÚ£¬·¢ÏÖÁ˺ܶàÎÊÌ⣬Ö÷ÒªÓÐÈçϼ¸´óÀàÎÊÌ⣺
1¡¢µ¯³ö´°¿ÚÎÊÌâ
¶ÔÓ ......