当前位置: 首页>>代码示例>>Java>>正文


Java X509Factory类代码示例

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


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

示例1: serializeSign

import sun.security.provider.X509Factory; //导入依赖的package包/类
public Buffer serializeSign(AuthCrypto authCrypto) throws CertificateEncodingException, IOException {
    Buffer payload = serializeMigrationResp();

    if (authCertificate != null) {
        String stringAuthCertificate = X509Factory.BEGIN_CERT + "\n"
                + new Buffer(authCertificate.getEncoded()).toBase64().replaceAll("(.{64})", "$1\n")
                + "\n" + X509Factory.END_CERT;

        BufferedString bufferedStringAuthCertificate = new BufferedString(stringAuthCertificate);
        payload.concat(bufferedStringAuthCertificate.serialize());

        Buffer signature = authCrypto.signWithPrivateKey(payload);
        payload.concat(signature);
    }
    else {
        throw new RuntimeException("authCertificate is not available!");
    }
    this.payload = payload;
    return super.serialize();
}
 
开发者ID:iotauth,项目名称:iotauth,代码行数:21,代码来源:MigrationRespMessage.java

示例2: readRFC1421Cert

import sun.security.provider.X509Factory; //导入依赖的package包/类
/**
 * read input stream as HEX-encoded DER-encoded bytes
 *
 * @param in InputStream to read
 * @returns DerValue corresponding to decoded HEX-encoded bytes
 * @throws IOException if stream can not be interpreted as RFC1421
 *                     encoded bytes
 */
private DerValue readRFC1421Cert(InputStream in) throws IOException {
    DerValue der = null;
    String line = null;
    BufferedReader certBufferedReader =
        new BufferedReader(new InputStreamReader(in, "ASCII"));
    try {
        line = certBufferedReader.readLine();
    } catch (IOException ioe1) {
        throw new IOException("Unable to read InputStream: " +
                              ioe1.getMessage());
    }
    if (line.equals(X509Factory.BEGIN_CERT)) {
        /* stream appears to be hex-encoded bytes */
        ByteArrayOutputStream decstream = new ByteArrayOutputStream();
        try {
            while ((line = certBufferedReader.readLine()) != null) {
                if (line.equals(X509Factory.END_CERT)) {
                    der = new DerValue(decstream.toByteArray());
                    break;
                } else {
                    decstream.write(Base64.getMimeDecoder().decode(line));
                }
            }
        } catch (IOException ioe2) {
            throw new IOException("Unable to read InputStream: "
                                  + ioe2.getMessage());
        }
    } else {
        throw new IOException("InputStream is not RFC1421 hex-encoded " +
                              "DER bytes");
    }
    return der;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:X509CertImpl.java

示例3: toImpl

import sun.security.provider.X509Factory; //导入依赖的package包/类
/**
 * Utility method to convert an arbitrary instance of X509Certificate
 * to a X509CertImpl. Does a cast if possible, otherwise reparses
 * the encoding.
 */
public static X509CertImpl toImpl(X509Certificate cert)
        throws CertificateException {
    if (cert instanceof X509CertImpl) {
        return (X509CertImpl)cert;
    } else {
        return X509Factory.intern(cert);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:X509CertImpl.java

示例4: toImpl

import sun.security.provider.X509Factory; //导入依赖的package包/类
/**
 * Utility method to convert an arbitrary instance of X509CRL
 * to a X509CRLImpl. Does a cast if possible, otherwise reparses
 * the encoding.
 */
public static X509CRLImpl toImpl(X509CRL crl)
        throws CRLException {
    if (crl instanceof X509CRLImpl) {
        return (X509CRLImpl)crl;
    } else {
        return X509Factory.intern(crl);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:X509CRLImpl.java

示例5: dumpCert

import sun.security.provider.X509Factory; //导入依赖的package包/类
/**
 * Writes an X.509 certificate in base64 or binary encoding to an output
 * stream.
 */
private void dumpCert(Certificate cert, PrintStream out)
    throws IOException, CertificateException
{
    if (rfc) {
        out.println(X509Factory.BEGIN_CERT);
        out.println(Base64.getMimeEncoder().encodeToString(cert.getEncoded()));
        out.println(X509Factory.END_CERT);
    } else {
        out.write(cert.getEncoded()); // binary
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:Main.java

示例6: readRFC1421Cert

import sun.security.provider.X509Factory; //导入依赖的package包/类
/**
 * read input stream as HEX-encoded DER-encoded bytes
 *
 * @param in InputStream to read
 * @returns DerValue corresponding to decoded HEX-encoded bytes
 * @throws IOException if stream can not be interpreted as RFC1421
 *                     encoded bytes
 */
private DerValue readRFC1421Cert(InputStream in) throws IOException {
    DerValue der = null;
    String line = null;
    BufferedReader certBufferedReader =
        new BufferedReader(new InputStreamReader(in, "ASCII"));
    try {
        line = certBufferedReader.readLine();
    } catch (IOException ioe1) {
        throw new IOException("Unable to read InputStream: " +
                              ioe1.getMessage());
    }
    if (line.equals(X509Factory.BEGIN_CERT)) {
        /* stream appears to be hex-encoded bytes */
        ByteArrayOutputStream decstream = new ByteArrayOutputStream();
        try {
            while ((line = certBufferedReader.readLine()) != null) {
                if (line.equals(X509Factory.END_CERT)) {
                    der = new DerValue(decstream.toByteArray());
                    break;
                } else {
                    decstream.write(Pem.decode(line));
                }
            }
        } catch (IOException ioe2) {
            throw new IOException("Unable to read InputStream: "
                                  + ioe2.getMessage());
        }
    } else {
        throw new IOException("InputStream is not RFC1421 hex-encoded " +
                              "DER bytes");
    }
    return der;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:42,代码来源:X509CertImpl.java

示例7: dumpCert

import sun.security.provider.X509Factory; //导入依赖的package包/类
/**
 * Writes an X.509 certificate in base64 or binary encoding to an output
 * stream.
 */
private void dumpCert(Certificate cert, PrintStream out)
    throws IOException, CertificateException
{
    if (rfc) {
        out.println(X509Factory.BEGIN_CERT);
        out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(cert.getEncoded()));
        out.println(X509Factory.END_CERT);
    } else {
        out.write(cert.getEncoded()); // binary
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:Main.java

示例8: main

import sun.security.provider.X509Factory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    String ks = System.getProperty("test.src", ".")
            + "/../../ssl/etc/keystore";
    String pass = "passphrase";
    String alias = "dummy";

    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(new FileInputStream(ks), pass.toCharArray());
    byte[] cert = keyStore.getCertificate(alias).getEncoded();

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    PrintStream pout = new PrintStream(bout);
    byte[] CRLF = new byte[] {'\r', '\n'};
    pout.println(X509Factory.BEGIN_CERT);
    for (int i=0; i<cert.length; i += 48) {
        int blockLen = (cert.length > i + 48) ? 48 : (cert.length - i);
        pout.println("!" + Base64.getEncoder()
                .encodeToString(Arrays.copyOfRange(cert, i, i + blockLen)));
    }
    pout.println(X509Factory.END_CERT);

    CertificateFactory cf = CertificateFactory.getInstance("X.509");

    try {
        cf.generateCertificate(new ByteArrayInputStream(bout.toByteArray()));
        throw new Exception("Should fail");
    } catch (CertificateException e) {
        // Good
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:BadPem.java

示例9: readRFC1421Cert

import sun.security.provider.X509Factory; //导入依赖的package包/类
/**
 * read input stream as HEX-encoded DER-encoded bytes
 *
 * @param in InputStream to read
 * @return DerValue corresponding to decoded HEX-encoded bytes
 * @throws IOException if stream can not be interpreted as RFC1421
 *                     encoded bytes
 */
private DerValue readRFC1421Cert(InputStream in) throws IOException {
    DerValue der = null;
    String line = null;
    BufferedReader certBufferedReader =
        new BufferedReader(new InputStreamReader(in, "ASCII"));
    try {
        line = certBufferedReader.readLine();
    } catch (IOException ioe1) {
        throw new IOException("Unable to read InputStream: " +
                              ioe1.getMessage());
    }
    if (line.equals(X509Factory.BEGIN_CERT)) {
        /* stream appears to be hex-encoded bytes */
        ByteArrayOutputStream decstream = new ByteArrayOutputStream();
        try {
            while ((line = certBufferedReader.readLine()) != null) {
                if (line.equals(X509Factory.END_CERT)) {
                    der = new DerValue(decstream.toByteArray());
                    break;
                } else {
                    decstream.write(Pem.decode(line));
                }
            }
        } catch (IOException ioe2) {
            throw new IOException("Unable to read InputStream: "
                                  + ioe2.getMessage());
        }
    } else {
        throw new IOException("InputStream is not RFC1421 hex-encoded " +
                              "DER bytes");
    }
    return der;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:X509CertImpl.java

示例10: main

import sun.security.provider.X509Factory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    String ks = System.getProperty("test.src", ".")
            + "/../../../../javax/net/ssl/etc/keystore";
    String pass = "passphrase";
    String alias = "dummy";

    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(new FileInputStream(ks), pass.toCharArray());
    byte[] cert = keyStore.getCertificate(alias).getEncoded();

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    PrintStream pout = new PrintStream(bout);
    byte[] CRLF = new byte[] {'\r', '\n'};
    pout.println(X509Factory.BEGIN_CERT);
    for (int i=0; i<cert.length; i += 48) {
        int blockLen = (cert.length > i + 48) ? 48 : (cert.length - i);
        pout.println("!" + Base64.getEncoder()
                .encodeToString(Arrays.copyOfRange(cert, i, i + blockLen)));
    }
    pout.println(X509Factory.END_CERT);

    CertificateFactory cf = CertificateFactory.getInstance("X.509");

    try {
        cf.generateCertificate(new ByteArrayInputStream(bout.toByteArray()));
        throw new Exception("Should fail");
    } catch (CertificateException e) {
        // Good
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:BadPem.java

示例11: main

import sun.security.provider.X509Factory; //导入依赖的package包/类
public static void main(String[] args) throws IOException, OperatorCreationException, NoSuchAlgorithmException {

		// ---------------------- CA Creation ----------------------
		// System.out.println("Generating Keys");
		KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");
		rsa.initialize(1024);
		KeyPair kp = rsa.generateKeyPair();

		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.YEAR, 100);

		// System.out.println("Getting data");
		byte[] pk = kp.getPublic().getEncoded();
		SubjectPublicKeyInfo bcPk = SubjectPublicKeyInfo.getInstance(pk);

		// System.out.println("Creating cert");
		X509v1CertificateBuilder certGen = new X509v1CertificateBuilder(new X500Name("CN=CA Cert"), BigInteger.ONE,
				new Date(), cal.getTime(), new X500Name("CN=CA Cert"), bcPk);

		X509CertificateHolder certHolder = certGen
				.build(new JcaContentSignerBuilder("SHA1withRSA").build(kp.getPrivate()));

		StringBuffer s = new StringBuffer();

		s.append(X509Factory.BEGIN_CERT + "\n");
		s.append(Base64Utils.base64Encode(certHolder.getEncoded()) + "\n");
		s.append(X509Factory.END_CERT);

		saveFile(s.toString().getBytes());

		// ---------------------- ISSUER Creation ----------------------

	}
 
开发者ID:demoiselle,项目名称:signer,代码行数:34,代码来源:CreateCA.java

示例12: dump

import sun.security.provider.X509Factory; //导入依赖的package包/类
/**
 * Writes the certificate in base64 encoded from to the print stream.
 * See http://tools.ietf.org/html/rfc4945#section-6.1 for more information
 * @param cert sertifcate to export
 * @param out stream to print it to
 * @throws java.io.IOException if io fails
 * @throws java.security.cert.CertificateException if certificate fails
 */
public static void dump(Certificate cert, PrintStream out) throws IOException,
        CertificateException {

    BASE64Encoder encoder = new BASE64Encoder();
    out.println(X509Factory.BEGIN_CERT);
    encoder.encodeBuffer(cert.getEncoded(), out);
    out.println(X509Factory.END_CERT);
}
 
开发者ID:GITNE,项目名称:icedtea-web,代码行数:17,代码来源:CertificateUtils.java

示例13: parseCertificate

import sun.security.provider.X509Factory; //导入依赖的package包/类
private static X509Certificate parseCertificate(String x509CertString)
{
    try {
        byte[] stringBytes = Base64.decode(x509CertString.replaceAll(X509Factory.BEGIN_CERT, "").replaceAll(X509Factory.END_CERT, ""));
        return (X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(stringBytes));
    } catch (CertificateException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:SAP,项目名称:SAPJamWorkPatternJIRAIntegration,代码行数:11,代码来源:JamConsumer.java


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