本文整理汇总了Java中org.bouncycastle.asn1.DERInputStream类的典型用法代码示例。如果您正苦于以下问题:Java DERInputStream类的具体用法?Java DERInputStream怎么用?Java DERInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DERInputStream类属于org.bouncycastle.asn1包,在下文中一共展示了DERInputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: readDERCertificate
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
private Certificate readDERCertificate(
InputStream in)
throws IOException
{
DERInputStream dIn = new DERInputStream(in);
ASN1Sequence seq = (ASN1Sequence)dIn.readObject();
if (seq.size() > 1
&& seq.getObjectAt(0) instanceof DERObjectIdentifier)
{
if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData))
{
sData = new SignedData(ASN1Sequence.getInstance(
(ASN1TaggedObject)seq.getObjectAt(1), true));
return new X509CertificateObject(
X509CertificateStructure.getInstance(
sData.getCertificates().getObjectAt(sDataObjectCount++)));
}
}
return new X509CertificateObject(
X509CertificateStructure.getInstance(seq));
}
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:25,代码来源:JDKX509CertificateFactory.java
示例2: generateCACertificate
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
public static X509Certificate generateCACertificate(String provider, X509Name subject, Date start, Date expired,
KeyPair pair, int numberOfCAs, String signartureAlgorthm) throws InvalidKeyException, NoSuchProviderException,
SignatureException, IOException {
// generate the certificate
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
certGen.setIssuerDN(subject);
certGen.setNotBefore(start);
certGen.setNotAfter(expired);
certGen.setSubjectDN(subject);
certGen.setPublicKey(pair.getPublic());
certGen.setSignatureAlgorithm(signartureAlgorthm);
certGen.addExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(numberOfCAs));
certGen.addExtension(X509Extensions.KeyUsage, true, new KeyUsage(KeyUsage.digitalSignature
| KeyUsage.keyCertSign | KeyUsage.cRLSign));
SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo((ASN1Sequence) new DERInputStream(
new ByteArrayInputStream(pair.getPublic().getEncoded())).readObject());
certGen.addExtension(X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifier(spki));
SubjectPublicKeyInfo apki = new SubjectPublicKeyInfo((ASN1Sequence) new DERInputStream(
new ByteArrayInputStream(pair.getPublic().getEncoded())).readObject());
certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifier(apki));
return certGen.generateX509Certificate(pair.getPrivate(), provider);
}
开发者ID:NCIP,项目名称:cagrid-core,代码行数:26,代码来源:CertUtil.java
示例3: createCRL
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
public static X509CRL createCRL(String provider, X509Certificate caCert, PrivateKey caKey, CRLEntry[] entries,
Date expires, String signatureAlgorithm) throws Exception {
X509V2CRLGenerator crlGen = new X509V2CRLGenerator();
Date now = new Date();
crlGen.setIssuerDN(new X509Name(caCert.getSubjectDN().getName()));
crlGen.setThisUpdate(now);
crlGen.setNextUpdate(expires);
crlGen.setSignatureAlgorithm(signatureAlgorithm);
for (int i = 0; i < entries.length; i++) {
crlGen.addCRLEntry(entries[i].getCertificateSerialNumber(), now, entries[i].getReason());
}
SubjectPublicKeyInfo apki = new SubjectPublicKeyInfo((ASN1Sequence) new DERInputStream(
new ByteArrayInputStream(caCert.getPublicKey().getEncoded())).readObject());
crlGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifier(apki));
crlGen.addExtension(X509Extensions.CRLNumber, false, new CRLNumber(BigInteger.valueOf(System
.currentTimeMillis())));
return crlGen.generateX509CRL(caKey, provider);
}
开发者ID:NCIP,项目名称:cagrid-core,代码行数:19,代码来源:CertUtil.java
示例4: derDecode
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
private DigestInfo derDecode(
byte[] encoding)
throws IOException
{
ByteArrayInputStream bIn = new ByteArrayInputStream(encoding);
DERInputStream dIn = new DERInputStream(bIn);
return new DigestInfo((ASN1Sequence)dIn.readObject());
}
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:10,代码来源:JDKDigestSignature.java
示例5: createPublicKeyFromDERStream
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
static PublicKey createPublicKeyFromDERStream(
InputStream in)
throws IOException
{
return createPublicKeyFromPublicKeyInfo(
new SubjectPublicKeyInfo((ASN1Sequence)(new DERInputStream(in).readObject())));
}
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:8,代码来源:JDKKeyFactory.java
示例6: createPrivateKeyFromDERStream
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
static PrivateKey createPrivateKeyFromDERStream(
InputStream in)
throws IOException
{
return createPrivateKeyFromPrivateKeyInfo(
new PrivateKeyInfo((ASN1Sequence)(new DERInputStream(in).readObject())));
}
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:8,代码来源:JDKKeyFactory.java
示例7: getKey
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
protected PrivateKey getKey(String alg, byte [] data)
throws GeneralSecurityException {
if (alg.equals("RSA")) {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(data);
DERInputStream derin = new DERInputStream(bis);
DERObject keyInfo = derin.readObject();
DERObjectIdentifier rsa_oid = PKCSObjectIdentifiers.rsaEncryption;
AlgorithmIdentifier rsa = new AlgorithmIdentifier(rsa_oid);
PrivateKeyInfo pkeyinfo = new PrivateKeyInfo(rsa, keyInfo);
DERObject derkey = pkeyinfo.getDERObject();
byte[] keyData = BouncyCastleUtil.toByteArray(derkey);
// The DER object needs to be mangled to
// create a proper ProvateKeyInfo object
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyData);
KeyFactory kfac = KeyFactory.getInstance("RSA");
return kfac.generatePrivate(spec);
} catch (IOException e) {
// that should never happen
return null;
}
} else {
return null;
}
}
开发者ID:swift-lang,项目名称:swift-k,代码行数:31,代码来源:BouncyCastleOpenSSLKey.java
示例8: setPublicKey
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
public void setPublicKey(
PublicKey key)
{
try
{
tbsGen.setSubjectPublicKeyInfo(new SubjectPublicKeyInfo((ASN1Sequence)new DERInputStream(
new ByteArrayInputStream(key.getEncoded())).readObject()));
}
catch (Exception e)
{
throw new IllegalArgumentException("unable to process key - " + e.toString());
}
}
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:14,代码来源:X509V1CertificateGenerator.java
示例9: readDERCRL
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
private CRL readDERCRL(
InputStream in)
throws IOException
{
DERInputStream dIn = new DERInputStream(in);
return new X509CRLObject(new CertificateList((ASN1Sequence)dIn.readObject()));
}
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:9,代码来源:JDKX509CertificateFactory.java
示例10: getEncodedX509Certificate
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
/**
* Return a DERObject containing the encoded certificate.
*
* @param cert the X509Certificate object to be encoded
*
* @return the DERObject
**/
private DERObject getEncodedX509Certificate( X509Certificate cert )
throws CertificateEncodingException
{
try {
ByteArrayInputStream inStream = new ByteArrayInputStream( cert.getEncoded() );
DERInputStream derInStream = new DERInputStream( inStream );
return derInStream.readObject();
} catch ( IOException ex ) {
throw new CertificateEncodingException( "IOException caught while encoding certificate\n" + ex.toString() );
}
}
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:19,代码来源:PKIXCertPath.java
示例11: derDecode
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
private BigInteger[] derDecode(
byte[] encoding)
throws IOException
{
ByteArrayInputStream bIn = new ByteArrayInputStream(encoding);
DERInputStream dIn = new DERInputStream(bIn);
ASN1Sequence s = (ASN1Sequence)dIn.readObject();
BigInteger[] sig = new BigInteger[2];
sig[0] = ((DERInteger)s.getObjectAt(0)).getValue();
sig[1] = ((DERInteger)s.getObjectAt(1)).getValue();
return sig;
}
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:16,代码来源:JDKDSASigner.java
示例12: toDERSequence
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
private static ASN1Sequence toDERSequence(
byte[] bytes)
{
try
{
ByteArrayInputStream bIn = new ByteArrayInputStream(bytes);
DERInputStream dIn = new DERInputStream(bIn);
return (ASN1Sequence)dIn.readObject();
}
catch (Exception e)
{
throw new IllegalArgumentException("badly encoded request");
}
}
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:16,代码来源:PKCS10CertificationRequest.java
示例13: getExtensionValue
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
/**
* Retrieves the actual value of the X.509 extension.
*
* @param certExtValue the DER-encoded OCTET string value of the extension.
* @return the decoded/actual value of the extension (the octets).
*/
public static byte[] getExtensionValue(byte [] certExtValue)
throws IOException {
ByteArrayInputStream inStream = new ByteArrayInputStream(certExtValue);
DERInputStream derInputStream = new DERInputStream(inStream);
DERObject object = derInputStream.readObject();
if (object instanceof ASN1OctetString) {
return ((ASN1OctetString)object).getOctets();
} else {
throw new IOException("Expected octet string");
}
}
开发者ID:NCIP,项目名称:cagrid-general,代码行数:18,代码来源:BouncyCastleUtil.java
示例14: generateIntermediateCACertificate
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
public static X509Certificate generateIntermediateCACertificate(String provider, X509Certificate cacert,
PrivateKey signerKey, X509Name subject, Date start, Date expired, PublicKey publicKey, String signatureAlgorithm)
throws InvalidKeyException, NoSuchProviderException, SignatureException, IOException {
int constraints = cacert.getBasicConstraints();
if (constraints <= 1) {
throw new SignatureException(
"The CA Certificate specified cannot generate an intermediate CA certificate (Basic Constraints :"
+ constraints + ")");
}
constraints = constraints - 1;
// generate the certificate
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
certGen.setIssuerDN(new X509Name(cacert.getSubjectDN().toString()));
certGen.setNotBefore(start);
certGen.setNotAfter(expired);
certGen.setSubjectDN(subject);
certGen.setPublicKey(publicKey);
certGen.setSignatureAlgorithm(signatureAlgorithm);
certGen.addExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(constraints));
certGen.addExtension(X509Extensions.KeyUsage, true, new KeyUsage(KeyUsage.digitalSignature
| KeyUsage.keyEncipherment | KeyUsage.keyCertSign));
SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo((ASN1Sequence) new DERInputStream(
new ByteArrayInputStream(publicKey.getEncoded())).readObject());
certGen.addExtension(X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifier(spki));
SubjectPublicKeyInfo apki = new SubjectPublicKeyInfo((ASN1Sequence) new DERInputStream(
new ByteArrayInputStream(cacert.getPublicKey().getEncoded())).readObject());
certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifier(apki));
return certGen.generateX509Certificate(signerKey, provider);
}
开发者ID:NCIP,项目名称:cagrid-core,代码行数:35,代码来源:CertUtil.java
示例15: generateCertificate
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
public static X509Certificate generateCertificate(String provider, X509Name subject, Date start, Date expired,
PublicKey publicKey, X509Certificate cacert, PrivateKey signerKey, String signatureAlgorithm, String policyId)
throws InvalidKeyException, NoSuchProviderException, SignatureException, IOException {
// create the certificate using the information in the request
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
certGen.setIssuerDN(new X509Name(cacert.getSubjectDN().getName()));
certGen.setNotBefore(start);
certGen.setNotAfter(expired);
certGen.setSubjectDN(subject);
certGen.setPublicKey(publicKey);
certGen.setSignatureAlgorithm(signatureAlgorithm);
certGen.addExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(false));
certGen.addExtension(X509Extensions.KeyUsage, true, new KeyUsage(KeyUsage.digitalSignature
| KeyUsage.keyEncipherment | KeyUsage.dataEncipherment | KeyUsage.nonRepudiation));
SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo((ASN1Sequence) new DERInputStream(
new ByteArrayInputStream(publicKey.getEncoded())).readObject());
certGen.addExtension(X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifier(spki));
SubjectPublicKeyInfo apki = new SubjectPublicKeyInfo((ASN1Sequence) new DERInputStream(
new ByteArrayInputStream(cacert.getPublicKey().getEncoded())).readObject());
certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifier(apki));
if (policyId != null) {
PolicyInformation pi = new PolicyInformation(new DERObjectIdentifier(policyId));
DERSequence seq = new DERSequence(pi);
certGen.addExtension(X509Extensions.CertificatePolicies.getId(), false, seq);
}
X509Certificate issuedCert = certGen.generateX509Certificate(signerKey, provider);
return issuedCert;
}
开发者ID:NCIP,项目名称:cagrid-core,代码行数:34,代码来源:CertUtil.java
示例16: testParseProxyCertInfo
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
public void testParseProxyCertInfo() throws Exception {
ProxyPolicy policy = new ProxyPolicy(testOid, testPolicy);
ProxyCertInfo info = new ProxyCertInfo(3,
policy);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
dOut.writeObject(info);
ByteArrayInputStream bIn =
new ByteArrayInputStream(bOut.toByteArray());
DERInputStream dIn = new DERInputStream(bIn);
DERObject obj = dIn.readObject();
assertTrue(obj instanceof ASN1Sequence);
ProxyCertInfo testInfo = new ProxyCertInfo((ASN1Sequence)obj);
assertEquals(3, testInfo.getPathLenConstraint());
assertEquals(testPolicy, testInfo.getProxyPolicy().getPolicyAsString());
assertEquals(testOid, testInfo.getProxyPolicy().getPolicyLanguage());
}
开发者ID:NCIP,项目名称:cagrid-general,代码行数:27,代码来源:ProxyCertInfoTest.java
示例17: createCertificate
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
/**
* Creates a proxy certificate from the certificate request. (Signs a
* certificate request creating a new certificate)
*
* @see #createProxyCertificate(X509Certificate, PrivateKey, PublicKey, int,
* int, X509ExtensionSet, String) createProxyCertificate
* @param certRequestInputStream
* the input stream to read the certificate request from.
* @param cert
* the issuer certificate
* @param privateKey
* the private key to sign the new certificate with.
* @param lifetime
* lifetime of the new certificate in seconds. If 0 (or less
* then) the new certificate will have the same lifetime as the
* issuing certificate.
* @param delegationMode
* the type of proxy credential to create
* @param extSet
* a set of X.509 extensions to be included in the new proxy
* certificate. Can be null. If delegation mode is
* {@link GSIConstants#GSI_3_RESTRICTED_PROXY
* GSIConstants.GSI_3_RESTRICTED_PROXY} then
* {@link org.globus.gsi.proxy.ext.ProxyCertInfoExtension
* ProxyCertInfoExtension} must be present in the extension set.
* @param cnValue
* the value of the CN component of the subject of the new
* certificate. If null, the defaults will be used depending on
* the proxy certificate type created.
* @return <code>X509Certificate</code> the new proxy certificate
* @exception IOException
* if error reading the certificate request
* @exception GeneralSecurityException
* if a security error occurs.
*/
public X509Certificate createCertificate(String provider, InputStream certRequestInputStream, X509Certificate cert,
PrivateKey privateKey, int lifetime, int delegationMode, X509ExtensionSet extSet, String cnValue,
String signatureAlgorithm) throws IOException, GeneralSecurityException {
DERInputStream derin = new DERInputStream(certRequestInputStream);
DERObject reqInfo = derin.readObject();
PKCS10CertificationRequest certReq = new PKCS10CertificationRequest((ASN1Sequence) reqInfo);
boolean rs = certReq.verify();
if (!rs) {
throw new GeneralSecurityException("Certificate request verification failed!");
}
return createProxyCertificate(provider, cert, privateKey, certReq.getPublicKey(), lifetime, delegationMode,
extSet, cnValue, signatureAlgorithm);
}
开发者ID:NCIP,项目名称:cagrid-core,代码行数:53,代码来源:BouncyCastleCertProcessingFactory.java
示例18: toDERObject
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
/**
* Converts the DER-encoded byte array into a
* <code>DERObject</code>.
*
* @param data the DER-encoded byte array to convert.
* @return the DERObject.
* @exception IOException if conversion fails
*/
public static DERObject toDERObject(byte[] data)
throws IOException {
ByteArrayInputStream inStream = new ByteArrayInputStream(data);
DERInputStream derInputStream = new DERInputStream(inStream);
return derInputStream.readObject();
}
开发者ID:NCIP,项目名称:cagrid-general,代码行数:15,代码来源:BouncyCastleUtil.java
示例19: createCertificate
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
/**
* Creates a proxy certificate from the certificate request.
* (Signs a certificate request creating a new certificate)
*
* @see #createProxyCertificate(X509Certificate, PrivateKey, PublicKey,
* int, int, X509ExtensionSet, String) createProxyCertificate
* @param certRequestInputStream the input stream to read the
* certificate request from.
* @param cert the issuer certificate
* @param privateKey the private key to sign the new
* certificate with.
* @param lifetime lifetime of the new certificate in seconds.
* If 0 (or less then) the new certificate will have the
* same lifetime as the issuing certificate.
* @param delegationMode the type of proxy credential to create
* @param extSet a set of X.509 extensions to be included in the new
* proxy certificate. Can be null. If delegation mode is
* {@link GSIConstants#GSI_3_RESTRICTED_PROXY
* GSIConstants.GSI_3_RESTRICTED_PROXY} then
* {@link org.globus.gsi.proxy.ext.ProxyCertInfoExtension
* ProxyCertInfoExtension} must be present in the extension
* set.
* @param cnValue the value of the CN component of the subject of
* the new certificate. If null, the defaults will be used
* depending on the proxy certificate type created.
* @return <code>X509Certificate</code> the new proxy certificate
* @exception IOException if error reading the certificate
* request
* @exception GeneralSecurityException if a security error
* occurs.
*/
public X509Certificate createCertificate(InputStream certRequestInputStream,
X509Certificate cert,
PrivateKey privateKey,
int lifetime,
int delegationMode,
X509ExtensionSet extSet,
String cnValue)
throws IOException, GeneralSecurityException {
DERInputStream derin = new DERInputStream(certRequestInputStream);
DERObject reqInfo = derin.readObject();
PKCS10CertificationRequest certReq =
new PKCS10CertificationRequest((ASN1Sequence)reqInfo);
boolean rs = certReq.verify();
if (!rs) {
throw new GeneralSecurityException("Certificate request verification failed!");
}
return createProxyCertificate(cert,
privateKey,
certReq.getPublicKey(),
lifetime,
delegationMode,
extSet,
cnValue);
}
开发者ID:NCIP,项目名称:cagrid-general,代码行数:60,代码来源:BouncyCastleCertProcessingFactory.java
示例20: loadCertificate
import org.bouncycastle.asn1.DERInputStream; //导入依赖的package包/类
/**
* Loads a X509 certificate from the specified input stream.
* Input stream must contain DER-encoded certificate.
*
* @param in the input stream to read the certificate from.
* @return <code>X509Certificate</code> the loaded certificate.
* @exception GeneralSecurityException if certificate failed to load.
*/
public X509Certificate loadCertificate(InputStream in)
throws IOException, GeneralSecurityException {
DERInputStream derin = new DERInputStream(in);
DERObject certInfo = derin.readObject();
ASN1Sequence seq = ASN1Sequence.getInstance(certInfo);
return new X509CertificateObject(new X509CertificateStructure(seq));
}
开发者ID:NCIP,项目名称:cagrid-general,代码行数:16,代码来源:BouncyCastleCertProcessingFactory.java
注:本文中的org.bouncycastle.asn1.DERInputStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论