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Òâ˼ÊǼ
Ïà¹ØÎĵµ£º
1. javaÊÇʲô
JavaÊÇÒ»ÖÖ±à³ÌÓïÑÔ£¬¸ú»ã±à¡¢C¡¢C++Ò»Ñù£¬ÊÇÓÃÓÚÈí¼þ±à³ÌµÄ¿ª·¢ÓïÑÔ¡£
JavaÊÇÒ»ÖÖ¿ª·¢¡¢ÔËÐл·¾³£¬java³ÌÐòµÄ¿ª·¢ÒªÒÀÀµÕâÖÖ»·¾³¡£
2. javaµÄÌصã
javaÓïÑÔ¾ßÓÐÓëƽ̨Î޹أ¬ÃæÏò¶ÔÏ󣬽¡×³ÐÔµÄÌصã
1).Óëƽ̨µÄÎÞ¹ØÐÔ
Óëjav ......
Ò»¡¢Àí½â¶àÏß³Ì
¶àÏß³ÌÊÇÕâÑùÒ»ÖÖ»úÖÆ£¬ËüÔÊÐíÔÚ³ÌÐòÖв¢·¢Ö´Ðжà¸öÖ¸ÁîÁ÷£¬Ã¿¸öÖ¸ÁîÁ÷¶¼³ÆΪһ¸öỊ̈߳¬±Ë´Ë¼ä»¥Ïà¶ÀÁ¢¡£Ïß³ÌÓÖ³ÆΪÇáÁ¿¼¶½ø³Ì£¬ËüºÍ½ø³ÌÒ»ÑùÓµÓжÀÁ¢µÄÖ´ÐпØÖÆ£¬ÓɲÙ×÷ϵͳ¸ºÔðµ÷¶È£¬Çø±ðÔÚÓÚÏß³ÌûÓжÀÁ¢µÄ´æ´¢¿Õ¼ä£¬¶øÊǺÍËùÊô½ø³ÌÖеÄÆäËüÏ̹߳²ÏíÒ»¸ö´æ´¢¿Õ¼ä£¬ÕâʹµÃÏ̼߳äµÄ ......
1 ×÷ÓÃÓò
javaÖÐ×÷ÓÃÓòµÄ·¶Î§ÓÉ»¨À¨ºÅ±êʾ¡£
2¹ØÓÚstatic
À¬»øÊÕ¼¯Æ÷Ö»ÖªµÀËѼ¯ÄÇЩÓÐnewÔËËã·û·ÖÅäµÄÄڴ棬²»ÖªµÀÈçºÎÊÍ·ÅÌØÊâÄÚ´æ¡£
Èç¹ûÀ¬»øÊÕ¼¯Æ÷×¼±¸»ØÊÕ¶ÔÏóµÄÄڴ棬ËüÊ×Ïȵ÷ÓÃfinalize()£¬¶øÇÒÖ»ÓÐÔÚÏÂÒ»´ÎÀ¬»øËѼ¯¹ý³ÌÖУ¬²Å»áÕæÕý»ØÊÕ¶ÔÏóµÄÄÚ´æ¡£ËùÒÔ˵Èç¹ûʹÓÃ
final ......
Thread-Per-Message PatternµÄ²ÎÓëÕߣº
1. Client£¨Î¯ÍÐÈË£©²ÎÓëÕß
Client²ÎÓëÕß»á¶ÔHost²ÎÓëÕß·¢³öÇëÇó¡£Client²ÎÓëÕß²¢²»ÖªµÀHost²ÎÓëÕß»áÈçºÎʵÏÖÕâ¸öÇëÇó¡£
2. Host²ÎÓëÕß
µ±Host²ÎÓëÕß½ÓÊÕµ½Client²ÎÓëÕßµÄÇëÇóʱ£¬»á½¨Á¢ÐµÄÏ̲߳¢Æô¶¯Ëü¡£
Õâ¸öеÄÏ ......
£¨1£©À༯µÄ²úÉúÄ¿µÄ
À༯¼òµ¥À´½²¾ÍÊÇÒ»¸ö¶¯Ì¬µÄ¶ÔÏóÊý×飬´Ë¶ÔÏóÊý×é¿ÉÒԸıä´óС£¬¿ÉÒÔÈÎÒâµÄʵÏÖ¶ÔÏóµÄÔö¼Ó¡¢É¾³ý¡¢Êä³ö¡£ËùÓеÄÀ༯´æ·Åjava.util°üÖС£
£¨2£©À༯µÄ»®·Ö
1¡¢´æ·Åµ¥Öµ£ºCollection
2¡¢´æ·ÅÒ»¶ÔÖµ£ºMap
3¡¢Êä³ö£ºIterator
Collection£¨´æ·Åµ¥Öµ£©
©ÀList
©¦©ÀLinkedList
© ......