• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PKCS10类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中sun.security.pkcs10.PKCS10的典型用法代码示例。如果您正苦于以下问题:Java PKCS10类的具体用法?Java PKCS10怎么用?Java PKCS10使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PKCS10类属于sun.security.pkcs10包,在下文中一共展示了PKCS10类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: main

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    PKCS10 req = new PKCS10(Base64.getMimeDecoder().decode(csrStr));

    // If PKCS9Attribute did not accept the PrintableString ASN.1 tag,
    // this would fail with an IOException
    Object attr = req.getAttributes().getAttribute("1.2.840.113549.1.9.2");

    // Check that the attribute exists
    if (attr == null) {
        throw new Exception("Attribute should not be null.");
    }

    System.out.println("Test passed.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:UnstructuredName.java


示例2: main

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
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");
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:PKCS10AttrEncoding.java


示例3: requestAndStoreDeviceCertificate

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
public static void requestAndStoreDeviceCertificate(Device device)
throws KeyStoreException, IOException {
	String path = properties.get("iot.dms.cert.domain").toString();
	path = normalizePath(path).concat("/v2/api/devices/").concat(device.getId())
		.concat("/authentication");

	KeyPair keyPair = keyStoreClient.generateKeyPair();
	boolean useTwoCommonNames = Boolean
		.parseBoolean(properties.get("use.two.common.names").toString());
	PKCS10 csRequest = keyStoreClient.createCSRequest(device, keyPair, useTwoCommonNames);

	String base64 = DatatypeConverter.printBase64Binary(csRequest.getEncoded());

	Authentication authentication = new Authentication();
	authentication.setType("clientCertificate");
	authentication.setCsr(base64);

	System.out.println("Do CSR request and store device certificate in the key store");

	String request = jsonParser.toJson(authentication, Authentication.class);

	String response = doSSLPost(path, request);

	Certificate certificate = keyStoreClient
		.retrieveCertificate(jsonParser.fromJson(response, Device.class));

	keyStoreClient.storeDeviceCertificate(certificate, keyPair, device);

	boolean storeAsPEMFile = Boolean
		.parseBoolean(properties.get("additionally.store.as.pem").toString());
	if (storeAsPEMFile) {
		String folder = properties.get("certificate.download.folder").toString();
		folder = normalizePath(folder).concat("/");
		System.out.println(
			"Store device certificate/private key as PEM files in folder: " + folder + "\n");
		keyStoreClient.storeDeviceCertificateAsPEM(certificate, keyPair, device, folder);
	}
}
 
开发者ID:SAP,项目名称:iot-starterkit,代码行数:39,代码来源:Main.java


示例4: doCertReq

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
/**
 * Creates a PKCS#10 cert signing request, corresponding to the
 * keys (and name) associated with a given alias.
 */
private void doCertReq(String alias, String sigAlgName, PrintStream out)
    throws Exception
{
    if (alias == null) {
        alias = keyAlias;
    }

    Pair<Key,char[]> objs = recoverKey(alias, storePass, keyPass);
    PrivateKey privKey = (PrivateKey)objs.fst;
    if (keyPass == null) {
        keyPass = objs.snd;
    }

    Certificate cert = keyStore.getCertificate(alias);
    if (cert == null) {
        MessageFormat form = new MessageFormat
            (rb.getString("alias.has.no.public.key.certificate."));
        Object[] source = {alias};
        throw new Exception(form.format(source));
    }
    PKCS10 request = new PKCS10(cert.getPublicKey());
    CertificateExtensions ext = createV3Extensions(null, null, v3ext, cert.getPublicKey(), null);
    // Attribute name is not significant
    request.getAttributes().setAttribute(X509CertInfo.EXTENSIONS,
            new PKCS10Attribute(PKCS9Attribute.EXTENSION_REQUEST_OID, ext));

    // Construct a Signature object, so that we can sign the request
    if (sigAlgName == null) {
        sigAlgName = getCompatibleSigAlgName(privKey.getAlgorithm());
    }

    Signature signature = Signature.getInstance(sigAlgName);
    signature.initSign(privKey);
    X500Name subject = dname == null?
            new X500Name(((X509Certificate)cert).getSubjectDN().toString()):
            new X500Name(dname);

    // Sign the request and base-64 encode it
    request.encodeAndSign(subject, signature);
    request.print(out);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:46,代码来源:Main.java


示例5: doPrintCertReq

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
private void doPrintCertReq(InputStream in, PrintStream out)
        throws Exception {

    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuffer sb = new StringBuffer();
    boolean started = false;
    while (true) {
        String s = reader.readLine();
        if (s == null) break;
        if (!started) {
            if (s.startsWith("-----")) {
                started = true;
            }
        } else {
            if (s.startsWith("-----")) {
                break;
            }
            sb.append(s);
        }
    }
    PKCS10 req = new PKCS10(Base64.getMimeDecoder().decode(new String(sb)));

    PublicKey pkey = req.getSubjectPublicKeyInfo();
    out.printf(rb.getString("PKCS.10.Certificate.Request.Version.1.0.Subject.s.Public.Key.s.format.s.key."),
            req.getSubjectName(), pkey.getFormat(), pkey.getAlgorithm());
    for (PKCS10Attribute attr: req.getAttributes().getAttributes()) {
        ObjectIdentifier oid = attr.getAttributeId();
        if (oid.equals((Object)PKCS9Attribute.EXTENSION_REQUEST_OID)) {
            CertificateExtensions exts = (CertificateExtensions)attr.getAttributeValue();
            if (exts != null) {
                printExtensions(rb.getString("Extension.Request."), exts, out);
            }
        } else {
            out.println("Attribute: " + attr.getAttributeId());
            PKCS9Attribute pkcs9Attr =
                    new PKCS9Attribute(attr.getAttributeId(),
                                       attr.getAttributeValue());
            out.print(pkcs9Attr.getName() + ": ");
            Object attrVal = attr.getAttributeValue();
            out.println(attrVal instanceof String[] ?
                        Arrays.toString((String[]) attrVal) :
                        attrVal);
        }
    }
    if (debug) {
        out.println(req);   // Just to see more, say, public key length...
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:49,代码来源:Main.java


示例6: doPrintCertReq

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
private void doPrintCertReq(InputStream in, PrintStream out)
        throws Exception {

    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuffer sb = new StringBuffer();
    boolean started = false;
    while (true) {
        String s = reader.readLine();
        if (s == null) break;
        if (!started) {
            if (s.startsWith("-----")) {
                started = true;
            }
        } else {
            if (s.startsWith("-----")) {
                break;
            }
            sb.append(s);
        }
    }
    PKCS10 req = new PKCS10(Pem.decode(new String(sb)));

    PublicKey pkey = req.getSubjectPublicKeyInfo();
    out.printf(rb.getString("PKCS.10.Certificate.Request.Version.1.0.Subject.s.Public.Key.s.format.s.key."),
            req.getSubjectName(), pkey.getFormat(), pkey.getAlgorithm());
    for (PKCS10Attribute attr: req.getAttributes().getAttributes()) {
        ObjectIdentifier oid = attr.getAttributeId();
        if (oid.equals((Object)PKCS9Attribute.EXTENSION_REQUEST_OID)) {
            CertificateExtensions exts = (CertificateExtensions)attr.getAttributeValue();
            if (exts != null) {
                printExtensions(rb.getString("Extension.Request."), exts, out);
            }
        } else {
            out.println("Attribute: " + attr.getAttributeId());
            PKCS9Attribute pkcs9Attr =
                    new PKCS9Attribute(attr.getAttributeId(),
                                       attr.getAttributeValue());
            out.print(pkcs9Attr.getName() + ": ");
            Object attrVal = attr.getAttributeValue();
            out.println(attrVal instanceof String[] ?
                        Arrays.toString((String[]) attrVal) :
                        attrVal);
        }
    }
    if (debug) {
        out.println(req);   // Just to see more, say, public key length...
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:49,代码来源:Main.java


示例7: doCertReq

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
/**
 * Creates a PKCS#10 cert signing request, corresponding to the
 * keys (and name) associated with a given alias.
 */
private void doCertReq(String alias, String sigAlgName, PrintStream out)
    throws Exception
{
    if (alias == null) {
        alias = keyAlias;
    }

    Pair<Key,char[]> objs = recoverKey(alias, storePass, keyPass);
    PrivateKey privKey = (PrivateKey)objs.fst;
    if (keyPass == null) {
        keyPass = objs.snd;
    }

    Certificate cert = keyStore.getCertificate(alias);
    if (cert == null) {
        MessageFormat form = new MessageFormat
            (rb.getString("alias.has.no.public.key.certificate."));
        Object[] source = {alias};
        throw new Exception(form.format(source));
    }
    PKCS10 request = new PKCS10(cert.getPublicKey());
    CertificateExtensions ext = createV3Extensions(null, null, v3ext, cert.getPublicKey(), null);
    // Attribute name is not significant
    request.getAttributes().setAttribute(X509CertInfo.EXTENSIONS,
            new PKCS10Attribute(PKCS9Attribute.EXTENSION_REQUEST_OID, ext));

    // Construct a Signature object, so that we can sign the request
    if (sigAlgName == null) {
        sigAlgName = getCompatibleSigAlgName(privKey);
    }

    Signature signature = Signature.getInstance(sigAlgName);
    signature.initSign(privKey);
    X500Name subject = dname == null?
            new X500Name(((X509Certificate)cert).getSubjectDN().toString()):
            new X500Name(dname);

    // Sign the request and base-64 encode it
    request.encodeAndSign(subject, signature);
    request.print(out);

    checkWeak(rb.getString("the.generated.certificate.request"), request);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:Main.java


示例8: doPrintCertReq

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
private void doPrintCertReq(InputStream in, PrintStream out)
        throws Exception {

    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuffer sb = new StringBuffer();
    boolean started = false;
    while (true) {
        String s = reader.readLine();
        if (s == null) break;
        if (!started) {
            if (s.startsWith("-----")) {
                started = true;
            }
        } else {
            if (s.startsWith("-----")) {
                break;
            }
            sb.append(s);
        }
    }
    PKCS10 req = new PKCS10(Pem.decode(new String(sb)));

    PublicKey pkey = req.getSubjectPublicKeyInfo();
    out.printf(rb.getString("PKCS.10.with.weak"),
            req.getSubjectName(),
            pkey.getFormat(),
            withWeak(pkey),
            withWeak(req.getSigAlg()));
    for (PKCS10Attribute attr: req.getAttributes().getAttributes()) {
        ObjectIdentifier oid = attr.getAttributeId();
        if (oid.equals(PKCS9Attribute.EXTENSION_REQUEST_OID)) {
            CertificateExtensions exts = (CertificateExtensions)attr.getAttributeValue();
            if (exts != null) {
                printExtensions(rb.getString("Extension.Request."), exts, out);
            }
        } else {
            out.println("Attribute: " + attr.getAttributeId());
            PKCS9Attribute pkcs9Attr =
                    new PKCS9Attribute(attr.getAttributeId(),
                                       attr.getAttributeValue());
            out.print(pkcs9Attr.getName() + ": ");
            Object attrVal = attr.getAttributeValue();
            out.println(attrVal instanceof String[] ?
                        Arrays.toString((String[]) attrVal) :
                        attrVal);
        }
    }
    if (debug) {
        out.println(req);   // Just to see more, say, public key length...
    }
    checkWeak(rb.getString("the.certificate.request"), req);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:53,代码来源:Main.java


示例9: checkWeak

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
private void checkWeak(String label, PKCS10 p10) {
    checkWeak(label, p10.getSigAlg(), p10.getSubjectPublicKeyInfo());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:Main.java


示例10: doCertReq

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
/**
 * Creates a PKCS#10 cert signing request, corresponding to the
 * keys (and name) associated with a given alias.
 */
private void doCertReq(String alias, String sigAlgName, PrintStream out)
    throws Exception
{
    if (alias == null) {
        alias = keyAlias;
    }

    Pair<Key,char[]> objs = recoverKey(alias, storePass, keyPass);
    PrivateKey privKey = (PrivateKey)objs.fst;
    if (keyPass == null) {
        keyPass = objs.snd;
    }

    Certificate cert = keyStore.getCertificate(alias);
    if (cert == null) {
        MessageFormat form = new MessageFormat
            (rb.getString("alias.has.no.public.key.certificate."));
        Object[] source = {alias};
        throw new Exception(form.format(source));
    }
    PKCS10 request = new PKCS10(cert.getPublicKey());
    CertificateExtensions ext = createV3Extensions(null, null, v3ext, cert.getPublicKey(), null);
    // Attribute name is not significant
    request.getAttributes().setAttribute(X509CertInfo.EXTENSIONS,
            new PKCS10Attribute(PKCS9Attribute.EXTENSION_REQUEST_OID, ext));

    // Construct a Signature object, so that we can sign the request
    if (sigAlgName == null) {
        sigAlgName = getCompatibleSigAlgName(privKey);
    }

    Signature signature = Signature.getInstance(sigAlgName);
    signature.initSign(privKey);
    X500Name subject = dname == null?
            new X500Name(((X509Certificate)cert).getSubjectDN().toString()):
            new X500Name(dname);

    // Sign the request and base-64 encode it
    request.encodeAndSign(subject, signature);
    request.print(out);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:46,代码来源:Main.java


示例11: doPrintCertReq

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
private void doPrintCertReq(InputStream in, PrintStream out)
        throws Exception {

    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuffer sb = new StringBuffer();
    boolean started = false;
    while (true) {
        String s = reader.readLine();
        if (s == null) break;
        if (!started) {
            if (s.startsWith("-----")) {
                started = true;
            }
        } else {
            if (s.startsWith("-----")) {
                break;
            }
            sb.append(s);
        }
    }
    PKCS10 req = new PKCS10(Pem.decode(new String(sb)));

    PublicKey pkey = req.getSubjectPublicKeyInfo();
    out.printf(rb.getString("PKCS.10.Certificate.Request.Version.1.0.Subject.s.Public.Key.s.format.s.key."),
            req.getSubjectName(), pkey.getFormat(), pkey.getAlgorithm());
    for (PKCS10Attribute attr: req.getAttributes().getAttributes()) {
        ObjectIdentifier oid = attr.getAttributeId();
        if (oid.equals(PKCS9Attribute.EXTENSION_REQUEST_OID)) {
            CertificateExtensions exts = (CertificateExtensions)attr.getAttributeValue();
            if (exts != null) {
                printExtensions(rb.getString("Extension.Request."), exts, out);
            }
        } else {
            out.println("Attribute: " + attr.getAttributeId());
            PKCS9Attribute pkcs9Attr =
                    new PKCS9Attribute(attr.getAttributeId(),
                                       attr.getAttributeValue());
            out.print(pkcs9Attr.getName() + ": ");
            Object attrVal = attr.getAttributeValue();
            out.println(attrVal instanceof String[] ?
                        Arrays.toString((String[]) attrVal) :
                        attrVal);
        }
    }
    if (debug) {
        out.println(req);   // Just to see more, say, public key length...
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:49,代码来源:Main.java


示例12: doCertReq

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
/**
 * Creates a PKCS#10 cert signing request, corresponding to the
 * keys (and name) associated with a given alias.
 */
private void doCertReq(String alias, String sigAlgName, PrintStream out)
    throws Exception
{
    if (alias == null) {
        alias = keyAlias;
    }

    Pair<Key,char[]> objs = recoverKey(alias, storePass, keyPass);
    PrivateKey privKey = (PrivateKey)objs.fst;
    if (keyPass == null) {
        keyPass = objs.snd;
    }

    Certificate cert = keyStore.getCertificate(alias);
    if (cert == null) {
        MessageFormat form = new MessageFormat
            (rb.getString("alias.has.no.public.key.certificate."));
        Object[] source = {alias};
        throw new Exception(form.format(source));
    }
    PKCS10 request = new PKCS10(cert.getPublicKey());
    CertificateExtensions ext = createV3Extensions(null, null, v3ext, cert.getPublicKey(), null);
    // Attribute name is not significant
    request.getAttributes().setAttribute(X509CertInfo.EXTENSIONS,
            new PKCS10Attribute(PKCS9Attribute.EXTENSION_REQUEST_OID, ext));

    // Construct a Signature object, so that we can sign the request
    if (sigAlgName == null) {
        sigAlgName = getCompatibleSigAlgName(privKey.getAlgorithm());
    }

    Signature signature = Signature.getInstance(sigAlgName);
    signature.initSign(privKey);
    X500Name subject = dname == null?
            new X500Name(((X509Certificate)cert).getSubjectDN().toString()):
            new X500Name(dname);

    // Sign the request and base-64 encode it
    request.encodeAndSign(subject, signature);
    request.print(out, systemLineEndings);

    checkWeak(rb.getString("the.generated.certificate.request"), request);
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:48,代码来源:Main.java


示例13: doPrintCertReq

import sun.security.pkcs10.PKCS10; //导入依赖的package包/类
private void doPrintCertReq(InputStream in, PrintStream out)
        throws Exception {

    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuffer sb = new StringBuffer();
    boolean started = false;
    while (true) {
        String s = reader.readLine();
        if (s == null) break;
        if (!started) {
            if (s.startsWith("-----")) {
                started = true;
            }
        } else {
            if (s.startsWith("-----")) {
                break;
            }
            sb.append(s);
        }
    }
    PKCS10 req = new PKCS10(Pem.decode(new String(sb)));

    PublicKey pkey = req.getSubjectPublicKeyInfo();
    out.printf(rb.getString("PKCS.10.with.weak"),
            req.getSubjectName(),
            pkey.getFormat(),
            withWeak(pkey),
            withWeak(req.getSigAlg()));
    for (PKCS10Attribute attr: req.getAttributes().getAttributes()) {
        ObjectIdentifier oid = attr.getAttributeId();
        if (oid.equals((Object)PKCS9Attribute.EXTENSION_REQUEST_OID)) {
            CertificateExtensions exts = (CertificateExtensions)attr.getAttributeValue();
            if (exts != null) {
                printExtensions(rb.getString("Extension.Request."), exts, out);
            }
        } else {
            out.println("Attribute: " + attr.getAttributeId());
            PKCS9Attribute pkcs9Attr =
                    new PKCS9Attribute(attr.getAttributeId(),
                                       attr.getAttributeValue());
            out.print(pkcs9Attr.getName() + ": ");
            Object attrVal = attr.getAttributeValue();
            out.println(attrVal instanceof String[] ?
                        Arrays.toString((String[]) attrVal) :
                        attrVal);
        }
    }
    if (debug) {
        out.println(req);   // Just to see more, say, public key length...
    }
    checkWeak(rb.getString("the.certificate.request"), req);
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:53,代码来源:Main.java



注:本文中的sun.security.pkcs10.PKCS10类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DnsSdTxtRecordListener类代码示例发布时间:2022-05-22
下一篇:
Java ScmManager类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap