e201. creating key objects from a set of digital signature algorithm (dsa) parameters.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 27 行

TXT
27
字号
The DSA requires three parameters to create a key pair - the prime (P), the subprime (Q), and the base (G). These three values are used to create a private key (called X) and a public key (called Y). 
This example creates a PrivateKey and PublicKey from a set of DSA parameters. 

    try {
        // Obtain the DSA parameters;
        // see e200 Getting the Digital Signature Algorithm (DSA) Parameters of a Key Pair
        BigInteger p = ...;
        BigInteger q = ...;
        BigInteger g = ...;
        BigInteger x = ...;
        BigInteger y = ...;
    
        // Create the DSA key factory
        KeyFactory keyFactory = KeyFactory.getInstance("DSA");
    
        // Create the DSA private key
        KeySpec privateKeySpec = new DSAPrivateKeySpec(x, p, q, g);
        PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec);
    
        // Create the DSA public key
        KeySpec publicKeySpec = new DSAPublicKeySpec(y, p, q, g);
        PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
    } catch (InvalidKeySpecException e) {
    } catch (NoSuchAlgorithmException e) {
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?