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


Java ASN1Object类代码示例

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


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

示例1: parse

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
/**
 * ANS.1 parser
 * 
 * @param dis
 * @throws IOException
 */
void parse(DerInputStream dis) throws IOException {
	ASN1Object[] dvs = (ASN1Object[]) dis.getSequence(2);
	for (int i = 0; i < dvs.length; i++) {
		switch (((DERTaggedObject) dvs[i]).getTagNo()) {
		case 0: // keytype[0] INTEGER
			keyType = ASN1Integer.getInstance(((DERTaggedObject) dvs[i]).getObject()).getValue().intValue();
			break;
		case 1: // keyvalue[1] OCTET STRING
			keyValue = DEROctetString.getInstance(((DERTaggedObject) dvs[i]).getObject()).getOctets();
			break;
		default:
			LOG.error("unknown tag:" + (((DERTaggedObject) dvs[i]).getTagNo() & (byte) 0x1F));
		}
	}
}
 
开发者ID:cbsit,项目名称:JaasLounge,代码行数:22,代码来源:EncryptionKey.java

示例2: equals

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
@Override
public boolean equals(Object paramObject) {

	if (paramObject == null) {
		return false;
	}

	try {
		return Arrays.equals(((ASN1Object) paramObject).getEncoded(), getEncoded());
	} catch (Exception e) {
		// ignore
	}
	return false;
}
 
开发者ID:kaikramer,项目名称:keystore-explorer,代码行数:15,代码来源:PolicyMapping.java

示例3: extractExtensionValue

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
/**
 * Extract a {@link ASN1OctetString} that represents the value of a given extension
 *
 * @param cert is X509 certificate out of which an extension should be extracted
 * @param Oid is the Object IDentifier for the extension
 * @return a {@link ASN1OctetString} that represents an extension or {@code null} if no such
 * extension is found.
 * @throws CertificateParsingException if a parsing error occurs
 */
public static ASN1OctetString extractExtensionValue(X509Certificate cert, String Oid)
    throws CertificateParsingException {
  byte[] extensionValue = cert.getExtensionValue(Oid);

  if (extensionValue == null || extensionValue.length == 0) {
    // Did not find extension
    return null;
  }

  ASN1Object asn1Object = getAsn1Object(extensionValue);
  if (asn1Object == null || !(asn1Object instanceof ASN1OctetString)) {
    throw new CertificateParsingException("Expected ASN1OctetString.");
  }

  return (ASN1OctetString) asn1Object;
}
 
开发者ID:TremoloSecurity,项目名称:OpenUnison,代码行数:26,代码来源:X509ExtensionParsingUtil.java

示例4: getKeyDescriptionSequence

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
private static ASN1Sequence getKeyDescriptionSequence(ASN1OctetString octet)
    throws CertificateParsingException {
  // Read out the Sequence
  ASN1Object asn1Object = X509ExtensionParsingUtil.getAsn1Object(octet.getOctets());
  if (asn1Object == null || !(asn1Object instanceof ASN1Sequence)) {
    throw new CertificateParsingException("Expected KeyDescription Sequence.");
  }
  ASN1Sequence sequence = (ASN1Sequence) asn1Object;

  if (sequence.size() != DESCRIPTION_LENGTH) {
    throw new CertificateParsingException("KeyDescription Sequence has " + sequence.size()
        + " elements.  Expected " + DESCRIPTION_LENGTH + " elements ");
  }

  return sequence;
}
 
开发者ID:TremoloSecurity,项目名称:OpenUnison,代码行数:17,代码来源:AndroidKeyStoreAttestation.java

示例5: toASN1Object

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
@Override
public ASN1Object toASN1Object() throws SmartCardException {
    ASN1EncodableVector certList = new ASN1EncodableVector();
    for (Certificate cert : certs) {
        ASN1EncodableVector essCertID1 = new ASN1EncodableVector();
        essCertID1.add(getCertificateHash(cert));
        essCertID1.add(getIssuerAndSerialForESSCertId(cert));
        DERSequence essCertID = new DERSequence(essCertID1);
        certList.add(essCertID);

    }

    DERSequence certListSeq = new DERSequence(certList);
    DERSequence signSeq = new DERSequence(certListSeq);
    return signSeq;
}
 
开发者ID:Turksat,项目名称:ESign,代码行数:17,代码来源:SigningCertificate.java

示例6: getObjectInTag

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
private ASN1Object getObjectInTag(int tagNo)
{
    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        DEREncodable obj = (DEREncodable)e.nextElement();

        if (obj instanceof ASN1TaggedObject)
        {
            ASN1TaggedObject tag = (ASN1TaggedObject)obj;
            if (tag.getTagNo() == tagNo)
            {
                return (ASN1Object)((DEREncodable)tag.getObject()).getDERObject();
            }
        }
    }
    return null;
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:20,代码来源:ECPrivateKeyStructure.java

示例7: decryptPKCS8Key

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
/**
 * Decrypts a DER-encoded private key in PKCS#8 format.
 *
 * @param encrypted
 *            Bytes of DER-encoded encrypted private key.
 * @param password
 *            Password to decrypt private key.
 *
 * @return ASN.1 encoded bytes of decrypted key.
 *
 * @throws CryptException
 *             On key decryption errors.
 */
private byte[] decryptPKCS8Key(final byte[] encrypted, final char[] password)
		throws CryptException {
	final EncryptionScheme scheme;
	try {
		final EncryptedPrivateKeyInfo ki = EncryptedPrivateKeyInfo
				.getInstance(ASN1Object.fromByteArray(encrypted));
		final AlgorithmIdentifier alg = ki.getEncryptionAlgorithm();
		if (PKCSObjectIdentifiers.id_PBES2.equals(alg.getObjectId())) {
			// PBES2 has following parameters:
			// {
			// {id-PBKDF2, {salt, iterationCount, keyLength (optional)}}
			// {encryptionAlgorithmOid, iv}
			// }
			final DERSequence pbeSeq = (DERSequence) alg.getParameters();
			final PBKDF2Parameters kdfParms = PBKDF2Parameters
					.decode((DERSequence) pbeSeq.getObjectAt(0));
			final PBES2CipherGenerator cipherGen = new PBES2CipherGenerator(
					(DERSequence) pbeSeq.getObjectAt(1));
			if (kdfParms.getLength() == 0) {
				kdfParms.setLength(cipherGen.getKeySize() / 8);
			}
			scheme = new PBES2EncryptionScheme(cipherGen.generate(),
					kdfParms);
		} else {
			// Use PBES1 encryption scheme to decrypt key
			scheme = new PBES1EncryptionScheme(PBES1Algorithm.fromOid(alg
					.getObjectId().getId()),
					PBEParameter.decode((DERSequence) alg.getParameters()));
		}
		return scheme.decrypt(password, ki.getEncryptedData());
	} catch (Exception e) {
		throw new CryptException("Failed decrypting PKCS#8 private key", e);
	}
}
 
开发者ID:shivam091,项目名称:Java-Security,代码行数:48,代码来源:PrivateKeyCredentialReader.java

示例8: decode

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
/** {@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);
	}
}
 
开发者ID:shivam091,项目名称:Java-Security,代码行数:25,代码来源:PublicKeyCredentialReader.java

示例9: parseRfc822

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
/**
 * Parse the given rfc822 addr-spec into DER encoded byte array
 * representation.
 * 
 * @param the
 *            rfc822 addr-spec in well known String format
 * 
 * @return the rfc822 addr-spec as byte array
 * 
 * @exception IOException
 *                if the String could not be parsed
 */
private static byte[] parseRfc822(String data) throws IOException
{
    int tmpInt = data.indexOf('@');
    if (tmpInt < 0 || tmpInt >= data.length() - 1)
    {
        throw new IOException("wrong format of rfc822Name:" + data);
    }
    // TODO more test for illegal charateers
    ASN1Object derData = new DERIA5String(data);
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    DEROutputStream derOutStream = new DEROutputStream(outStream);
    derOutStream.writeObject(derData);
    derOutStream.close();
    return outStream.toByteArray();
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:28,代码来源:CertUtil.java

示例10: setSubject

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
/**
 * Sets the subject criterion. The specified distinguished name must match
 * the subject distinguished name in the <code>X509Certificate</code>. If
 * null, any subject distinguished name will do.<br />
 * <br />
 * If <code>subjectDN</code> is not <code>null</code>, it should
 * contain a single DER encoded distinguished name, as defined in X.501. For
 * the ASN.1 notation for this structure, see
 * {@link #setIssuer(byte []) setIssuer(byte [] issuerDN)}.<br />
 * <br />
 * Uses {@link org.bouncycastle.asn1.ASN1InputStream ASN1InputStream},
 * {@link org.bouncycastle.asn1.ASN1Object ASN1Object},
 * {@link org.bouncycastle.asn1.ASN1Sequence ASN1Sequence},
 * {@link org.bouncycastle.asn1.x509.X509Name X509Name}
 * 
 * @param subjectDN
 *            a byte array containing the distinguished name in ASN.1 DER
 *            format (or <code>null</code>)
 * 
 * @exception IOException
 *                if an encoding error occurs (incorrect form for DN)
 */
public void setSubject(byte[] subjectDN) throws IOException
{
    if (subjectDN == null)
    {
        this.subjectDN = null;
        this.subjectDNX509 = null;
    }
    else
    {
        ByteArrayInputStream inStream = new ByteArrayInputStream(subjectDN);
        ASN1InputStream derInStream = new ASN1InputStream(inStream);
        ASN1Object obj = derInStream.readObject();

        if (obj instanceof ASN1Sequence)
        {
            this.subjectDNX509 = new X509Name((ASN1Sequence)obj);
        }
        else
        {
            throw new IOException("parsing error");
        }
        this.subjectDN = (byte[])subjectDN.clone();
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:47,代码来源:X509CertSelector.java

示例11: toString

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
/**
 * Return a printable representation of this
 * <code>PolicyQualifierInfo</code>.<br />
 * <br />
 * Uses {@link org.bouncycastle.asn1.ASN1InputStream ASN1InputStream},
 * {@link org.bouncycastle.asn1.ASN1Object ASN1Object}
 * 
 * @return a <code>String</code> describing the contents of this
 *         <code>PolicyQualifierInfo</code>
 */
public String toString()
{
    StringBuffer s = new StringBuffer();
    s.append("PolicyQualifierInfo: [\n");
    s.append("qualifierID: ").append(id).append('\n');
    try
    {
        ByteArrayInputStream inStream = new ByteArrayInputStream(qualifier);
        ASN1InputStream derInStream = new ASN1InputStream(inStream);
        ASN1Object derObject = derInStream.readObject();
        s
                .append("  qualifier:\n").append(ASN1Dump.dumpAsString(derObject))
                .append('\n');
    }
    catch (IOException ex)
    {
        s.append(ex.getMessage());
    }
    s.append("qualifier: ").append(id).append('\n');
    s.append(']');
    return s.toString();
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:33,代码来源:PolicyQualifierInfo.java

示例12: checkNameConstraints

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
/**
 * Check given DER encoded nameConstraints for correct decoding. Currently
 * only basic DER decoding test.<br />
 * <br />
 * <b>TODO: implement more testing.</b>
 * 
 * @param data
 *            the DER encoded nameConstrains to be checked or
 *            <code>null</code>
 * @exception IllegalArgumentException
 *                if the check failed.
 */
private void checkNameConstraints(byte[] data)
{
    if (data != null)
    {
        try
        {
            ByteArrayInputStream inStream = new ByteArrayInputStream(data);
            ASN1InputStream derInStream = new ASN1InputStream(inStream);
            ASN1Object derObject = derInStream.readObject();
            if (!(derObject instanceof ASN1Sequence))
            {
                throw new IllegalArgumentException(
                        "nameConstraints parameter decoding error");
            }
        }
        catch (IOException ex)
        {
            throw new IllegalArgumentException(
                    "nameConstraints parameter decoding error: " + ex);
        }
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:35,代码来源:TrustAnchor.java

示例13: getInstance

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
/**
 * Returns an instance of <code>ProxyCertInfo</code> from given object.
 * 
 * @param obj
 *            the object to create the instance from.
 * @return <code>ProxyCertInfo</code> instance.
 * @exception IllegalArgumentException
 *                if unable to convert the object to
 *                <code>ProxyCertInfo</code> instance.
 */
public static ProxyCertInfo getInstance(Object obj) {
	if (obj instanceof ProxyCertInfo)
		return (ProxyCertInfo) obj;

	if (obj instanceof byte[]) {
		try {
			obj = ASN1Object.fromByteArray((byte[]) obj);
		} catch (IOException ignored) {
		}
	}

	if (obj instanceof ASN1Sequence)
		return new ProxyCertInfo((ASN1Sequence) obj);

	throw new IllegalArgumentException("unknown object in factory");
}
 
开发者ID:NCIP,项目名称:cagrid2,代码行数:27,代码来源:ProxyCertInfo.java

示例14: ECPrivateKey

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
public ECPrivateKey(
    BigInteger key,
    DERBitString publicKey,
    ASN1Object parameters)
{
    byte[] bytes = BigIntegers.asUnsignedByteArray(key);

    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new ASN1Integer(1));
    v.add(new DEROctetString(bytes));

    if (parameters != null)
    {
        v.add(new DERTaggedObject(true, 0, parameters));
    }

    if (publicKey != null)
    {
        v.add(new DERTaggedObject(true, 1, publicKey));
    }

    seq = new DERSequence(v);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:ECPrivateKey.java

示例15: convertValueToObject

import org.bouncycastle.asn1.ASN1Object; //导入依赖的package包/类
/**
 * Convert the value of the passed in extension to an object
 * @param ext the extension to parse
 * @return the object the value string contains
 * @exception IllegalArgumentException if conversion is not possible
 */
public static ASN1Object convertValueToObject(
    X509Extension ext)
    throws IllegalArgumentException
{
    try
    {
        return ASN1Object.fromByteArray(ext.getValue().getOctets());
    }
    catch (IOException e)
    {
        throw new IllegalArgumentException("can't convert extension: " +  e);
    }
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:20,代码来源:X509Extension.java


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