Atitit.rsa密鑰生成器的attilax總結

Atitit.rsa密鑰生成器attilax總結算法

 

1.1. 密鑰生成器 1dom

1.2. 生成固定的密鑰 2ui

1.2.1. 設置或重置 SecureRandom 對象的隨機數種子 2spa

1.3. 密鑰結構 2.net

 

1.1. 密鑰生成器

public static Map<String, Object>  initKey2(String md5_deta) throws Exception{code

     /** RSA算法要求有一個可信任的隨機數源 */orm

    SecureRandom secureRandom=  SecureRandom.getInstance("12345678");對象

       //實例化密鑰對生成器blog

       KeyPairGenerator keyPairGen=KeyPairGenerator.getInstance(KEY_ALGORITHM);md5

       // 初始化密鑰對生成器

       //keyPairGen.initialize(KEY_SIZE);

       // 初始化的時候固定隨機源的值

       keyPairGen.initialize(KEY_SIZE, secureRandom);

       // 生成密鑰對

       KeyPair keyPair=keyPairGen.generateKeyPair();

       //公鑰

       RSAPublicKey publicKey=(RSAPublicKey)keyPair.getPublic();

       //私鑰

       RSAPrivateKey privateKey=(RSAPrivateKey) keyPair.getPrivate();

       // 獲得公鑰字符串

    //   String publicKeyString = Base64.encode(publicKey.getEncoded());

       // 獲得私鑰字符串

    //   String privateKeyString = Base64.encode(privateKey.getEncoded());

           // 封裝密鑰

           Map<String, Object> keyMap=new HashMap<String,Object>(2);

           keyMap.put(PUBLIC_KEY, publicKey);

           keyMap.put(PRIVATE_KEY, privateKey);

           return keyMap;

   }

 

 

1.2. 生成固定的密鑰

 

1.2.1. 設置或重置 SecureRandom 對象的隨機數種子

除非調用程序在調用 getInstance 方法後接着調用 setSeed 方法,不然 SecureRandom 實現方法將會徹底使發生器的內部狀態隨機化:

 

    SecureRandom secureRandom=  new SecureRandom("fixx".getBytes("gbk"));

     

       // 初始化的時候固定隨機源的值

       keyPairGen.initialize(KEY_SIZE, secureRandom);

 

方法

  SecureRandom secureRandom=new SecureRandom();

    secureRandom.setSeed(1235);

   

1.3. 密鑰結構

 

pubkey_md5:A603B693B6BB434FA3004B7618F3B9BB

{

"RSAPublicKey":{

"algorithm":"RSA",

"algorithmId":{

"name":"RSA",

"oID":{}

},

"encoded":"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIQqS1ReGEE/ySM+PyZxS41HzDBul0xIkscNkqd+qZejQ3r2LmUw4BYoTC7CHsFjwk6V/a0Imwz3KsvtsOffii8CAwEAAQ==",

"encodedInternal":"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIQqS1ReGEE/ySM+PyZxS41HzDBul0xIkscNkqd+qZejQ3r2LmUw4BYoTC7CHsFjwk6V/a0Imwz3KsvtsOffii8CAwEAAQ==",

"format":"X.509",

"modulus":6922053815168845700711519855384250277549407002769104068590208637227720690525493166882866757882836951436668086793282219943697989363887338835452201051064879,

"publicExponent":65537

},

"RSAPrivateKey":{

"algorithm":"RSA",

"algorithmId":{"$ref":"$.RSAPublicKey.algorithmId"},

"crtCoefficient":12637801240537467651180025414810617094531052210139246616910795005297730540027,

"destroyed":false,

"encoded":"MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAhCpLVF4YQT/JIz4/JnFLjUfMMG6XTEiSxw2Sp36pl6NDevYuZTDgFihMLsIewWPCTpX9rQibDPcqy+2w59+KLwIDAQABAkBNu1Zcw46+aZaR/N1FbeMCsBSe85xWyGRTYF891dhHD21HERkZyfm4BooN0VjKohPbatUmRazWfuGKc9hap7Y5AiEAwfjL1el1zq+YOlTqKsJ5oF8/b+55SLD4dasZpAvC+S0CIQCubcsND+yJrFMFDNyQoY+w2GZuEegDQ3gs37R6N4TySwIgSJZfSTylbmQ9tk6Clt/R/hbGuY9nabF4OSh/Xulb3D0CIB2VO2nUuI5E7rOdkc7px7/7g6vJV6suBzS9IBPWVLLvAiAb8L307PiDD9i/IvEbM8uz7RC+YRUr4DNRx66jEkBR+w==",

"format":"PKCS#8",

"modulus":6922053815168845700711519855384250277549407002769104068590208637227720690525493166882866757882836951436668086793282219943697989363887338835452201051064879,

"primeExponentP":32832209798077781373384495608799993732908171300012237207496150976697489677373,

"primeExponentQ":13380742877797692883283997671823302246667615946650995680559515864045072986863,

"primeP":87735964670198717955861353260506633609525089601993964928345575802643155188013,

"primeQ":78896423390213891002409658607133041775965411272664534765346737848126131204683,

"privateExponent":4071143999659477204234638949384102521448065869993059131846279077802500786064340926073856151160133264216762031129885857399234406337799168487767767633081913,

"publicExponent":65537

}

}

 

 

取模運算符「%」的做  modulus

 

做者:: 綽號:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿爾 拉帕努伊 ) 

漢字名:艾提拉(艾龍)   EMAIL:1466519819@qq.com

轉載請註明來源: http://blog.cnb.net/attilax

Atiend

相關文章
相關標籤/搜索