KeyPairGenerator:生成的公钥参数

时间:2015-04-22 07:18:04

标签: public-key

我生成了一个公钥,并打印了公钥的参数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

1 个答案:

答案 0 :(得分:1)

作为Wikipedia Article on DSA states

  

算法参数(p,q,g)可以在系统的不同用户之间共享。

我检查过,我的系统也得到完全相同的p,q和g。

同样Oracle docs也说明参数。