Example usage for java.security.interfaces RSAPublicKey getParams

List of usage examples for java.security.interfaces RSAPublicKey getParams

Introduction

In this page you can find the example usage for java.security.interfaces RSAPublicKey getParams.

Prototype

default AlgorithmParameterSpec getParams() 

Source Link

Document

Returns the parameters associated with this key.

Usage

From source file:com.verisignlabs.dnssec.cl.KeyInfoTool.java

public void execute() throws Exception {
    for (int i = 0; i < state.keynames.length; ++i) {
        String keyname = state.keynames[i];
        DnsKeyPair key = BINDKeyUtils.loadKey(keyname, null);
        DNSKEYRecord dnskey = key.getDNSKEYRecord();
        DnsKeyAlgorithm dnskeyalg = DnsKeyAlgorithm.getInstance();

        boolean isSEP = (dnskey.getFlags() & DNSKEYRecord.Flags.SEP_KEY) != 0;

        System.out.println(keyname + ":");
        System.out.println("Name: " + dnskey.getName());
        System.out.println("SEP: " + isSEP);

        System.out.println("Algorithm: " + dnskeyalg.algToString(dnskey.getAlgorithm()) + " ("
                + dnskey.getAlgorithm() + ")");
        System.out.println("ID: " + dnskey.getFootprint());
        System.out.println("KeyFileBase: " + BINDKeyUtils.keyFileBase(key));
        int basetype = dnskeyalg.baseType(dnskey.getAlgorithm());
        switch (basetype) {
        case DnsKeyAlgorithm.RSA: {
            RSAPublicKey pub = (RSAPublicKey) key.getPublic();
            System.out.println("RSA Public Exponent: " + pub.getPublicExponent());
            System.out.println("RSA Modulus: " + pub.getModulus());
            break;
        }/*from   w  w w .j av a2 s  .  c o  m*/
        case DnsKeyAlgorithm.DSA: {
            DSAPublicKey pub = (DSAPublicKey) key.getPublic();
            System.out.println("DSA base (G): " + pub.getParams().getG());
            System.out.println("DSA prime (P): " + pub.getParams().getP());
            System.out.println("DSA subprime (Q): " + pub.getParams().getQ());
            System.out.println("DSA public (Y): " + pub.getY());
            break;
        }
        }
        if (state.keynames.length - i > 1) {
            System.out.println();
        }
    }
}

From source file:uk.ac.ed.epcc.webapp.ssh.PublicKeyReaderUtil.java

/** format a key (of the types supported by the {@link #load(String)} method. 
 * // w  w  w. j ava2 s  .  c  o m
 * @param key
 * @return public key string
 * @throws PublicKeyParseException 
 * @throws IOException 
 */
public static String format(PublicKey key) throws PublicKeyParseException, IOException {
    StringBuilder sb = new StringBuilder();
    String alg = key.getAlgorithm();
    if (alg.equalsIgnoreCase("RSA")) {
        RSAPublicKey pub = (RSAPublicKey) key;
        sb.append(SSH2_RSA_KEY);
        sb.append(" ");
        SSH2ByteBuffer buf = new SSH2ByteBuffer();
        buf.writeString(SSH2_RSA_KEY);
        buf.writeMPint(pub.getPublicExponent());
        buf.writeMPint(pub.getModulus());
        sb.append(Base64.encodeBase64String(buf.toByteArray()));
    } else if (alg.equalsIgnoreCase("DSA")) {
        DSAPublicKey pub = (DSAPublicKey) key;
        sb.append(SSH2_DSA_KEY);
        sb.append(" ");
        SSH2ByteBuffer buf = new SSH2ByteBuffer();
        buf.writeString(SSH2_DSA_KEY);
        DSAParams params = pub.getParams();
        buf.writeMPint(params.getP());
        buf.writeMPint(params.getQ());
        buf.writeMPint(params.getG());
        buf.writeMPint(pub.getY());
        sb.append(Base64.encodeBase64String(buf.toByteArray()));
    } else {
        throw new PublicKeyParseException(ErrorCode.UNKNOWN_PUBLIC_KEY_FILE_FORMAT);
    }
    return sb.toString();
}