本文整理了Java中org.bouncycastle.asn1.ASN1Object.fromByteArray()
方法的一些代码示例,展示了ASN1Object.fromByteArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ASN1Object.fromByteArray()
方法的具体详情如下:
包路径:org.bouncycastle.asn1.ASN1Object
类名称:ASN1Object
方法名:fromByteArray
暂无
代码示例来源:origin: com.google.code.jscep/jscep-api
private X509CertificateStructure getCertificate() {
try {
ASN1Sequence seq = (ASN1Sequence) ASN1Object.fromByteArray(identity.getEncoded());
X509CertificateStructure x509 = new X509CertificateStructure(seq);
return x509;
} catch (CertificateEncodingException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.google.code.jscep/jscep-api
private DEREncodableVector getCertificatesVector() throws IOException {
final DEREncodableVector v = new ASN1EncodableVector();
for (Certificate cert : certs) {
try {
v.add(ASN1Object.fromByteArray(cert.getEncoded()));
} catch (CertificateEncodingException e) {
// This is thrown if an encoding error occurs.
throw new IOException(e);
}
}
return v;
}
代码示例来源:origin: net.jradius/jradius-extended
/**
* Create a private key parameter from a PKCS8 PrivateKeyInfo encoding.
*
* @param privateKeyInfoData the PrivateKeyInfo encoding
* @return a suitable private key parameter
* @throws IOException on an error decoding the key
*/
public static AsymmetricKeyParameter createKey(
byte[] privateKeyInfoData)
throws IOException
{
return createKey(
PrivateKeyInfo.getInstance(
ASN1Object.fromByteArray(privateKeyInfoData)));
}
代码示例来源:origin: com.hynnet/jradius-extended
/**
* Create a private key parameter from a PKCS8 PrivateKeyInfo encoding.
*
* @param privateKeyInfoData the PrivateKeyInfo encoding
* @return a suitable private key parameter
* @throws IOException on an error decoding the key
*/
public static AsymmetricKeyParameter createKey(
byte[] privateKeyInfoData)
throws IOException
{
return createKey(
PrivateKeyInfo.getInstance(
ASN1Object.fromByteArray(privateKeyInfoData)));
}
代码示例来源:origin: com.google.code.jscep/jscep-api
private DEREncodableVector getCRLsVector() throws IOException {
final DEREncodableVector v = new ASN1EncodableVector();
for (CRL crl : crls) {
final X509CRL x509crl = (X509CRL) crl;
try {
v.add(ASN1Object.fromByteArray(x509crl.getEncoded()));
} catch (CRLException e) {
// This is thrown if an encoding error occurs.
throw new IOException(e);
}
}
return v;
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
public String getNetscapeCertComment( X509Certificate cert )
{
try {
byte[] value = cert.getExtensionValue( MiscObjectIdentifiers.netscapeCertComment.getId() );
if ( value == null ) {
return null;
}
return ASN1Object.fromByteArray( value ).toString();
} catch ( IOException ex ) {
throw new CryptoFailure( "Unable to extract NetscapeCertComment from X509Certificate extensions", ex );
}
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
public GeneralNames getIssuerAlternativeNames( X509Certificate cert )
{
try {
byte[] value = cert.getExtensionValue( X509Extensions.IssuerAlternativeName.getId() );
if ( value == null ) {
return null;
}
return GeneralNames.getInstance( ASN1Object.fromByteArray( ( ( ASN1OctetString ) ASN1Object.fromByteArray( value ) ).getOctets() ) );
} catch ( IOException ex ) {
throw new CryptoFailure( "Unable to extract IssuerAlternativeName from X509Certificate extensions", ex );
}
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
public GeneralNames getSubjectAlternativeNames( X509Certificate cert )
{
try {
byte[] value = cert.getExtensionValue( X509Extensions.SubjectAlternativeName.getId() );
if ( value == null ) {
return null;
}
return GeneralNames.getInstance( ASN1Object.fromByteArray( ( ( ASN1OctetString ) ASN1Object.fromByteArray( value ) ).getOctets() ) );
} catch ( IOException ex ) {
throw new CryptoFailure( "Unable to extract SubjectAlternativeName from X509Certificate extensions", ex );
}
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
public BasicConstraints getBasicConstraints( X509Certificate cert )
{
try {
byte[] value = cert.getExtensionValue( X509Extensions.BasicConstraints.getId() );
if ( value == null ) {
return null;
}
return BasicConstraints.getInstance( ASN1Object.fromByteArray( ( ( ASN1OctetString ) ASN1Object.fromByteArray( value ) ).getOctets() ) );
// return BasicConstraints.getInstance( ASN1Object.fromByteArray( value ) );
} catch ( IOException ex ) {
throw new CryptoFailure( "Unable to extract BasicConstraints from X509Certificate extensions", ex );
}
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
public byte[] getSubjectKeyIdentifier( X509Certificate cert )
{
try {
byte[] value = cert.getExtensionValue( X509Extensions.SubjectKeyIdentifier.getId() );
if ( value == null ) {
return null;
}
byte[] octets = ( ( ASN1OctetString ) ASN1Object.fromByteArray( value ) ).getOctets();
return SubjectKeyIdentifier.getInstance( ASN1Object.fromByteArray( octets ) ).getKeyIdentifier();
} catch ( IOException ex ) {
throw new CryptoFailure( "Unable to extract SubjectKeyIdentifier from X509Certificate extensions", ex );
}
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
public Interval getPrivateKeyUsagePeriod( X509Certificate cert )
{
try {
byte[] value = cert.getExtensionValue( X509Extensions.PrivateKeyUsagePeriod.getId() );
if ( value == null ) {
return null;
}
PrivateKeyUsagePeriod privKeyUsagePeriod = PrivateKeyUsagePeriod.getInstance( ASN1Object.fromByteArray( value ) );
SimpleDateFormat derDateFormat = new SimpleDateFormat( "yyyyMMddHHmmssz" );
Date notBefore = derDateFormat.parse( privKeyUsagePeriod.getNotBefore().getTime() );
Date notAfter = derDateFormat.parse( privKeyUsagePeriod.getNotAfter().getTime() );
return new Interval( new DateTime( notBefore ), new DateTime( notAfter ) );
} catch ( ParseException ex ) {
throw new CryptoFailure( "Unable to extract PrivateKeyUsagePeriod from X509Certificate extensions", ex );
} catch ( IOException ex ) {
throw new CryptoFailure( "Unable to extract PrivateKeyUsagePeriod from X509Certificate extensions", ex );
}
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
public Set<PolicyInformation> getCertificatePolicies( X509Certificate cert )
{
try {
byte[] value = cert.getExtensionValue( X509Extensions.CertificatePolicies.getId() );
if ( value == null ) {
return Collections.emptySet();
}
ASN1Sequence policiesSequence = ( ASN1Sequence ) ASN1Object.fromByteArray( value );
Set<PolicyInformation> certPolicies = new LinkedHashSet<PolicyInformation>();
for ( int idx = 0; idx < policiesSequence.size(); idx++ ) {
PolicyInformation policy = PolicyInformation.getInstance( policiesSequence.getObjectAt( idx ) );
certPolicies.add( policy );
}
return certPolicies;
} catch ( IOException ex ) {
throw new CryptoFailure( "Unable to extract CertificatePolicies from X509Certificate extensions", ex );
}
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
@SuppressWarnings( "SetReplaceableByEnumSet" )
public Set<NetscapeCertType> getNetscapeCertTypes( X509Certificate cert )
{
try {
byte[] value = cert.getExtensionValue( MiscObjectIdentifiers.netscapeCertType.getId() );
if ( value == null ) {
return Collections.emptySet();
}
byte[] asn1octets = ( ( ASN1OctetString ) ASN1Object.fromByteArray( value ) ).getOctets();
int nctIntValue = new org.bouncycastle.asn1.misc.NetscapeCertType( ( DERBitString ) ASN1Object.fromByteArray( asn1octets ) ).intValue();
Set<NetscapeCertType> netscapeCertTypes = new LinkedHashSet<NetscapeCertType>();
for ( NetscapeCertType eachCertType : NetscapeCertType.values() ) {
if ( ( nctIntValue & eachCertType.getIntValue() ) == eachCertType.getIntValue() ) {
netscapeCertTypes.add( eachCertType );
}
}
return netscapeCertTypes;
} catch ( IOException ex ) {
throw new CryptoFailure( "Unable to extract NetscapeCertType from X509Certificate extensions", ex );
}
}
代码示例来源:origin: com.google.code.jscep/jscep-api
private EnvelopedData getEnvelopedData(DEREncodable content) throws IOException {
// According to PKCS #9, data consists of an octet string.
final ASN1OctetString octetString = (ASN1OctetString) content;
final byte[] octets = octetString.getOctets();
final ContentInfo contentInfo = ContentInfo.getInstance(ASN1Object.fromByteArray(octets));
final DERObjectIdentifier contentType = contentInfo.getContentType();
if (contentType.equals(CMSObjectIdentifiers.envelopedData) == false) {
LOGGER.warning("Expected envelopedData ContentInfo, was " + contentType);
}
return new EnvelopedData((ASN1Sequence) contentInfo.getContent());
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
public NameConstraints getNameConstraints( X509Certificate cert )
{
try {
byte[] value = cert.getExtensionValue( X509Extensions.NameConstraints.getId() );
if ( value == null ) {
return null;
}
return new NameConstraints( ( ASN1Sequence ) ASN1Object.fromByteArray( value ) );
} catch ( IOException ex ) {
throw new CryptoFailure( "Unable to extract NameConstraints from X509Certificate extensions", ex );
}
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
@SuppressWarnings( "SetReplaceableByEnumSet" )
public Set<ExtendedKeyUsage> getExtendedKeyUsages( X509Certificate cert )
{
try {
byte[] value = cert.getExtensionValue( X509Extensions.ExtendedKeyUsage.getId() );
if ( value == null ) {
return Collections.emptySet();
}
byte[] asn1octets = ( ( ASN1OctetString ) ASN1Object.fromByteArray( value ) ).getOctets();
org.bouncycastle.asn1.x509.ExtendedKeyUsage usages = org.bouncycastle.asn1.x509.ExtendedKeyUsage.getInstance( ( ASN1Sequence ) ASN1Sequence.fromByteArray( asn1octets ) );
Set<ExtendedKeyUsage> keyUsages = new LinkedHashSet<ExtendedKeyUsage>();
for ( ExtendedKeyUsage eachPossible : ExtendedKeyUsage.values() ) {
if ( usages.hasKeyPurposeId( eachPossible.getKeyPurposeId() ) ) {
keyUsages.add( eachPossible );
}
}
return keyUsages;
} catch ( IOException ex ) {
throw new CryptoFailure( "Unable to extract ExtendedKeyUsages from X509Certificate extensions", ex );
}
}
代码示例来源:origin: edu.vt.middleware/vt-crypt
/** {@inheritDoc} */
protected PublicKey decode(final byte[] encoded)
throws CryptException
{
try {
final ASN1Sequence seq = (ASN1Sequence) ASN1Object.fromByteArray(encoded);
final ASN1Sequence innerSeq = (ASN1Sequence) seq.getObjectAt(0);
final DEREncodable algId = innerSeq.getObjectAt(0);
final String algorithm;
if (RSA_ID.equals(algId)) {
algorithm = "RSA";
} else if (EC_ID.equals(algId)) {
algorithm = "EC";
} else if (DSA_ID.equals(algId)) {
algorithm = "DSA";
} else {
throw new CryptException(
"Unsupported public key algorithm ID " + algId);
}
return
CryptProvider.getKeyFactory(algorithm).generatePublic(
new X509EncodedKeySpec(encoded));
} catch (Exception e) {
throw new CryptException("Invalid public key.", e);
}
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
public Set<PolicyConstraint> getPolicyConstraints( X509Certificate cert )
{
try {
byte[] value = cert.getExtensionValue( X509Extensions.PolicyConstraints.getId() );
if ( value == null ) {
return Collections.emptySet();
}
ASN1Sequence constraintsSequence = ( ASN1Sequence ) ASN1Object.fromByteArray( value );
Set<PolicyConstraint> constraints = new LinkedHashSet<PolicyConstraint>();
for ( int idx = 0; idx < constraintsSequence.size(); idx++ ) {
DERTaggedObject asn1Constraint = ( DERTaggedObject ) constraintsSequence.getObjectAt( idx );
DERInteger skipCerts = new DERInteger( ( ( DEROctetString ) asn1Constraint.getObject() ).getOctets() );
PolicyConstraint constraint = new PolicyConstraint();
switch ( asn1Constraint.getTagNo() ) {
case 0:
constraint.setRequireExplicitPolicy( skipCerts.getValue().intValue() );
break;
case 1:
constraint.setInhibitPolicyMapping( skipCerts.getValue().intValue() );
}
constraints.add( constraint );
}
return constraints;
} catch ( IOException ex ) {
throw new CryptoFailure( "Unable to extract PolicyConstraints from X509Certificate extensions", ex );
}
}
代码示例来源:origin: com.google.code.jscep/jscep-api
private RecipientInfo toRecipientInfo(X509Certificate cert, SecretKey key) throws CertificateEncodingException, IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException {
PublicKey pubKey = cert.getPublicKey();
TBSCertificateStructure tbs = TBSCertificateStructure.getInstance(ASN1Object.fromByteArray(cert.getTBSCertificate()));
AlgorithmIdentifier keyEncAlg = tbs.getSubjectPublicKeyInfo().getAlgorithmId();
Cipher keyCipher = Cipher.getInstance("RSA");
keyCipher.init(Cipher.WRAP_MODE, pubKey);
ASN1OctetString encKey = new DEROctetString(keyCipher.wrap(key));
ASN1InputStream aIn = new ASN1InputStream(cert.getTBSCertificate());
tbs = TBSCertificateStructure.getInstance(aIn.readObject());
IssuerAndSerialNumber encSid = new IssuerAndSerialNumber(tbs.getIssuer(), tbs.getSerialNumber().getValue());
return new RecipientInfo(new KeyTransRecipientInfo(new RecipientIdentifier(encSid), keyEncAlg, encKey));
}
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
public Set<PolicyMapping> getPolicyMappings( X509Certificate cert )
{
try {
byte[] value = cert.getExtensionValue( X509Extensions.PolicyMappings.getId() );
if ( value == null ) {
return Collections.emptySet();
}
ASN1Sequence mappingsSequence = ( ASN1Sequence ) ASN1Object.fromByteArray( value );
Set<PolicyMapping> mappings = new LinkedHashSet<PolicyMapping>();
for ( int idx = 0; idx < mappingsSequence.size(); idx++ ) {
ASN1Sequence seq = ( ASN1Sequence ) mappingsSequence.getObjectAt( idx );
PolicyMapping mapping = new PolicyMapping();
if ( seq.size() > 0 ) {
mapping.setIssuerDomainPolicyOID( ( ( DERObjectIdentifier ) seq.getObjectAt( 0 ) ).getId() );
}
if ( seq.size() > 1 ) {
mapping.setIssuerDomainPolicyOID( ( ( DERObjectIdentifier ) seq.getObjectAt( 1 ) ).getId() );
}
mappings.add( mapping );
}
return mappings;
} catch ( IOException ex ) {
throw new CryptoFailure( "Unable to extract PolicyMappings from X509Certificate extensions", ex );
}
}
内容来源于网络,如有侵权,请联系作者删除!