Search in sources :

Example 1 with X509Key

use of sun.security.x509.X509Key in project jdk8u_jdk by JetBrains.

the class P11ECUtil method x509EncodeECPublicKey.

static byte[] x509EncodeECPublicKey(ECPoint w, ECParameterSpec params) throws InvalidKeySpecException {
    ECPublicKeySpec keySpec = new ECPublicKeySpec(w, params);
    X509Key key = (X509Key) ECGeneratePublic(keySpec);
    return key.getEncoded();
}
Also used : X509Key(sun.security.x509.X509Key)

Example 2 with X509Key

use of sun.security.x509.X509Key in project jdk8u_jdk by JetBrains.

the class PKCS10AttrEncoding method main.

public static void main(String[] args) throws Exception {
    // initializations
    int len = ids.length;
    Object[] values = { new ObjectIdentifier("1.2.3.4"), new GregorianCalendar(1970, 1, 25, 8, 56, 7).getTime(), "challenging" };
    for (int j = 0; j < len; j++) {
        constructedMap.put(ids[j], values[j]);
    }
    X500Name subject = new X500Name("cn=Test");
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
    String sigAlg = "DSA";
    keyGen.initialize(512);
    KeyPair pair = keyGen.generateKeyPair();
    X509Key publicKey = (X509Key) pair.getPublic();
    PrivateKey privateKey = pair.getPrivate();
    Signature signature = Signature.getInstance(sigAlg);
    signature.initSign(privateKey);
    // Create the PKCS10 request
    PKCS10Attribute[] attrs = new PKCS10Attribute[len];
    for (int j = 0; j < len; j++) {
        attrs[j] = new PKCS10Attribute(ids[j], values[j]);
    }
    PKCS10 req = new PKCS10(publicKey, new PKCS10Attributes(attrs));
    System.out.println("List of attributes in constructed PKCS10 " + "request: ");
    checkAttributes(req.getAttributes().getElements());
    // Encode the PKCS10 request and generate another PKCS10 request from
    // the encoded byte array
    req.encodeAndSign(subject, signature);
    PKCS10 resp = new PKCS10(req.getEncoded());
    System.out.println("List of attributes in DER encoded PKCS10 Request:");
    checkAttributes(resp.getAttributes().getElements());
    if (failedCount > 0) {
        throw new RuntimeException("Attributes Compared : Failed");
    }
    System.out.println("Attributes Compared : Pass");
}
Also used : PKCS10Attribute(sun.security.pkcs10.PKCS10Attribute) KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) PKCS10Attributes(sun.security.pkcs10.PKCS10Attributes) GregorianCalendar(java.util.GregorianCalendar) X500Name(sun.security.x509.X500Name) KeyPairGenerator(java.security.KeyPairGenerator) X509Key(sun.security.x509.X509Key) PKCS10(sun.security.pkcs10.PKCS10) Signature(java.security.Signature) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Aggregations

X509Key (sun.security.x509.X509Key)2 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 PrivateKey (java.security.PrivateKey)1 Signature (java.security.Signature)1 GregorianCalendar (java.util.GregorianCalendar)1 PKCS10 (sun.security.pkcs10.PKCS10)1 PKCS10Attribute (sun.security.pkcs10.PKCS10Attribute)1 PKCS10Attributes (sun.security.pkcs10.PKCS10Attributes)1 ObjectIdentifier (sun.security.util.ObjectIdentifier)1 X500Name (sun.security.x509.X500Name)1