Atitit.rsa密钥生成器的attilax总结

Atitit.rsa密钥生成器的attilax总结

1.1. 密钥生成器 1

1.2. 生成固定的密钥 2

1.2.1.
设置或重置 SecureRandom
对象的随机数种子 2

1.3. 密钥结构 2

1.1. 密钥生成器

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

/** RSA算法要求有一个可信任的随机数源 */

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

//实例化密钥对生成器

KeyPairGenerator keyPairGen=KeyPairGenerator.getInstance(KEY_ALGORITHM);

// 初始化密钥对生成器

//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.csdn.net/attilax

Atiend

上一篇:day27_反射


下一篇:hadoop 2.2.0 集群部署 坑