KeyPairGenerator : 生成 public 个关键参数
KeyPairGenerator : generated public key parameters
我生成了一个 public 密钥,并打印了 public 密钥的参数 p、q、g 和 y。我执行了程序几次,发现只有 y 值发生变化,而 p、q、g 的值没有变化。
为什么会这样?
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
public class Key {
public static void main (String args[]) {
try {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA","SUN");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG","SUN");
keyGen.initialize(1024, random);
KeyPair pair = keyGen.generateKeyPair();
PublicKey pubKey = pair.getPublic();
PrivateKey privKey = pair.getPrivate();
System.out.println("Public Key: " + pubKey);
} catch (Exception e) {
}
}
}
输出
Public Key: Sun DSA Public Key
Parameters:
p:
fd7f5381 1d751229 52df4a9c 2eece4e7 f611b752 3cef4400 c31e3f80 b6512669
455d4022 51fb593d 8d58fabf c5f5ba30 f6cb9b55 6cd7813b 801d346f f26660b7
6b9950a5 a49f9fe8 047b1022 c24fbba9 d7feb7c6 1bf83b57 e7c6a8a6 150f04fb
83f6d3c5 1ec30235 54135a16 9132f675 f3ae2b61 d72aeff2 2203199d d14801c7
q:
9760508f 15230bcc b292b982 a2eb840b f0581cf5
g:
f7e1a085 d69b3dde cbbcab5c 36b857b9 7994afbb fa3aea82 f9574c0b 3d078267
5159578e bad4594f e6710710 8180b449 167123e8 4c281613 b7cf0932 8cc8a6e1
3c167a8b 547c8d28 e0a3ae1e 2bb3a675 916ea37f 0bfa2135 62f1fb62 7a01243b
cca4f1be a8519089 a883dfe1 5ae59f06 928b665e 807b5525 64014c3b fecf492a
y:
ddd3c52e 670efbe0 6755e3cd 13b28019 06565e33 fcab6d9a b2ab548c e361f971
2a771a8b 0bd7d58e 7c09d310 d8004d2a de8833fd b1a60d59 4441d60d 3d051ceb
0f9d3a08 ba71b804 4a42a901 98acedf7 10feba49 f2bb5274 934b63c1 1561bd81
1f3bd998 d6475a72 2df9c963 7bcdc53c 86078a8a fa74c903 4d184bc9 20c67aaa
作为 Wikipedia Article on DSA states:
The algorithm parameters (p, q, g) may be shared between different users of the system.
我检查了一下,我的系统上也得到了完全相同的 p、q 和 g。
此外 Oracle docs 也说明了参数。
我生成了一个 public 密钥,并打印了 public 密钥的参数 p、q、g 和 y。我执行了程序几次,发现只有 y 值发生变化,而 p、q、g 的值没有变化。 为什么会这样?
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
public class Key {
public static void main (String args[]) {
try {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA","SUN");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG","SUN");
keyGen.initialize(1024, random);
KeyPair pair = keyGen.generateKeyPair();
PublicKey pubKey = pair.getPublic();
PrivateKey privKey = pair.getPrivate();
System.out.println("Public Key: " + pubKey);
} catch (Exception e) {
}
}
}
输出
Public Key: Sun DSA Public Key
Parameters:
p:
fd7f5381 1d751229 52df4a9c 2eece4e7 f611b752 3cef4400 c31e3f80 b6512669
455d4022 51fb593d 8d58fabf c5f5ba30 f6cb9b55 6cd7813b 801d346f f26660b7
6b9950a5 a49f9fe8 047b1022 c24fbba9 d7feb7c6 1bf83b57 e7c6a8a6 150f04fb
83f6d3c5 1ec30235 54135a16 9132f675 f3ae2b61 d72aeff2 2203199d d14801c7
q:
9760508f 15230bcc b292b982 a2eb840b f0581cf5
g:
f7e1a085 d69b3dde cbbcab5c 36b857b9 7994afbb fa3aea82 f9574c0b 3d078267
5159578e bad4594f e6710710 8180b449 167123e8 4c281613 b7cf0932 8cc8a6e1
3c167a8b 547c8d28 e0a3ae1e 2bb3a675 916ea37f 0bfa2135 62f1fb62 7a01243b
cca4f1be a8519089 a883dfe1 5ae59f06 928b665e 807b5525 64014c3b fecf492a
y:
ddd3c52e 670efbe0 6755e3cd 13b28019 06565e33 fcab6d9a b2ab548c e361f971
2a771a8b 0bd7d58e 7c09d310 d8004d2a de8833fd b1a60d59 4441d60d 3d051ceb
0f9d3a08 ba71b804 4a42a901 98acedf7 10feba49 f2bb5274 934b63c1 1561bd81
1f3bd998 d6475a72 2df9c963 7bcdc53c 86078a8a fa74c903 4d184bc9 20c67aaa
作为 Wikipedia Article on DSA states:
The algorithm parameters (p, q, g) may be shared between different users of the system.
我检查了一下,我的系统上也得到了完全相同的 p、q 和 g。
此外 Oracle docs 也说明了参数。