本文整理汇总了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();
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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
}
}
示例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;
}
示例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
}
}
示例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
}
}
示例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;
}
示例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
}
}
示例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 ----------------------
}
示例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);
}
示例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;
}