本文整理汇总了Java中org.bouncycastle.asn1.DEREncodable类的典型用法代码示例。如果您正苦于以下问题:Java DEREncodable类的具体用法?Java DEREncodable怎么用?Java DEREncodable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DEREncodable类属于org.bouncycastle.asn1包,在下文中一共展示了DEREncodable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dumpAsString
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
/**
* Dump out the object as a string.
*
* @param obj the object to be dumped
* @param verbose if true, dump out the contents of octet and bit strings.
* @return the resulting string.
*/
public static String dumpAsString(
Object obj,
boolean verbose)
{
StringBuffer buf = new StringBuffer();
if (obj instanceof DERObject)
{
_dumpAsString("", verbose, (DERObject)obj, buf);
}
else if (obj instanceof DEREncodable)
{
_dumpAsString("", verbose, ((DEREncodable)obj).getDERObject(), buf);
}
else
{
return "unknown object type " + obj.toString();
}
return buf.toString();
}
示例2: getSigAlgID
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
static AlgorithmIdentifier getSigAlgID(
DERObjectIdentifier sigOid,
String algorithmName)
{
if (noParams.contains(sigOid))
{
return new AlgorithmIdentifier(sigOid);
}
algorithmName = Strings.toUpperCase(algorithmName);
if (params.containsKey(algorithmName))
{
return new AlgorithmIdentifier(sigOid, (DEREncodable)params.get(algorithmName));
}
else
{
return new AlgorithmIdentifier(sigOid, new DERNull());
}
}
示例3: addExtension
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
/**
* Add an extension with the given oid and the passed in value to be included
* in the OCTET STRING associated with the extension.
*
* @param oid OID for the extension.
* @param critical true if critical, false otherwise.
* @param value the ASN.1 object to be included in the extension.
*/
public void addExtension(
DERObjectIdentifier oid,
boolean critical,
DEREncodable value)
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
try
{
dOut.writeObject(value);
}
catch (IOException e)
{
throw new IllegalArgumentException("error encoding value: " + e);
}
this.addExtension(oid, critical, bOut.toByteArray());
}
示例4: addExtension
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
/**
* add a given extension field for the standard extensions tag (tag 0)
*/
public void addExtension(
DERObjectIdentifier OID,
boolean critical,
DEREncodable value)
{
if (extensions == null)
{
extensions = new Hashtable();
extOrdering = new Vector();
}
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
try
{
dOut.writeObject(value);
}
catch (IOException e)
{
throw new IllegalArgumentException("error encoding value: " + e);
}
this.addExtension(OID, critical, bOut.toByteArray());
}
示例5: getObjectInTag
import org.bouncycastle.asn1.DEREncodable; //导入依赖的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;
}
示例6: getRoleAuthorityAsString
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
/**
* Gets the role authority as a <code>String[]</code> object.
* @return the role authority of this RoleSyntax represented as a
* <code>String[]</code> array.
*/
public String[] getRoleAuthorityAsString()
{
if(roleAuthority == null)
{
return new String[0];
}
GeneralName[] names = roleAuthority.getNames();
String[] namesString = new String[names.length];
for(int i = 0; i < names.length; i++)
{
DEREncodable value = names[i].getName();
if(value instanceof DERString)
{
namesString[i] = ((DERString)value).getString();
}
else
{
namesString[i] = value.toString();
}
}
return namesString;
}
示例7: fromASN1Set
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
/**
* Creates a new instance from an ASN.1 SET of SEQUENCE representing the
* AttributeTypeAndValue type of section 2 of RFC 2253.
*
* @param set
* Set from which to create new RDN instance.
*
* @return New RDN from encoded data.
*/
public static RelativeDistinguishedName fromASN1Set(final ASN1Set set) {
final List<AttributeTypeAndValue> values = new ArrayList<AttributeTypeAndValue>();
for (int i = 0; i < set.size(); i++) {
final DEREncodable value = set.getObjectAt(i);
if (!(value instanceof ASN1Sequence)) {
throw new IllegalArgumentException(
"Value must be ASN.1 sequence.");
}
final ASN1Sequence seq = (ASN1Sequence) value;
if (seq.size() != 2) {
throw new IllegalArgumentException("Illegal sequence size "
+ seq.size());
}
if (!(seq.getObjectAt(0) instanceof DERObjectIdentifier)) {
throw new IllegalArgumentException(
"First sequence item must be OID.");
}
values.add(new AttributeTypeAndValue(seq.getObjectAt(0).toString(),
seq.getObjectAt(1).toString()));
}
return new RelativeDistinguishedName(values);
}
示例8: createPolicyInformationList
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
/**
* Creates a {@link PolicyInformationList} object from DER data.
*
* @param enc
* DER encoded policy information data; must be <code>
* ASN1Sequence</code>.
*
* @return Certificate policy information listing.
*/
public static PolicyInformationList createPolicyInformationList(
final DEREncodable enc) {
if (!(enc instanceof ASN1Sequence)) {
throw new IllegalArgumentException("Expected ASN1Sequence but got "
+ enc);
}
final ASN1Sequence seq = (ASN1Sequence) enc;
final List<PolicyInformation> policies = new ArrayList<PolicyInformation>(
seq.size());
for (int i = 0; i < seq.size(); i++) {
policies.add(createPolicyInformation(seq.getObjectAt(i)));
}
return new PolicyInformationList(
policies.toArray(new PolicyInformation[policies.size()]));
}
示例9: createPolicyInformation
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
/**
* Creates a {@link PolicyInformation} object from DER data.
*
* @param enc
* DER encoded policy information data.
*
* @return Certificate policy information object.
*/
public static PolicyInformation createPolicyInformation(
final DEREncodable enc) {
final org.bouncycastle.asn1.x509.PolicyInformation info = org.bouncycastle.asn1.x509.PolicyInformation
.getInstance(enc);
final ASN1Sequence encodedQualifiers = info.getPolicyQualifiers();
if (encodedQualifiers != null) {
final int size = encodedQualifiers.size();
final List<PolicyQualifierInfo> qualifiers = new ArrayList<PolicyQualifierInfo>(
size);
for (int i = 0; i < size; i++) {
final DEREncodable item = encodedQualifiers.getObjectAt(i);
qualifiers.add(createPolicyQualifierInfo(item));
}
return new PolicyInformation(info.getPolicyIdentifier().toString(),
qualifiers.toArray(new PolicyQualifierInfo[size]));
} else {
return new PolicyInformation(info.getPolicyIdentifier().toString());
}
}
示例10: createAuthorityKeyIdentifier
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
/**
* Creates a {@link AuthorityKeyIdentifier} object from DER data.
*
* @param enc
* DER encoded authority key identifier data.
*
* @return Authority key identifier.
*/
public static AuthorityKeyIdentifier createAuthorityKeyIdentifier(
final DEREncodable enc) {
final org.bouncycastle.asn1.x509.AuthorityKeyIdentifier aki = org.bouncycastle.asn1.x509.AuthorityKeyIdentifier
.getInstance(enc);
KeyIdentifier keyIdentifier = null;
if (aki.getKeyIdentifier() != null) {
keyIdentifier = new KeyIdentifier(aki.getKeyIdentifier());
}
GeneralNameList issuerNames = null;
if (aki.getAuthorityCertIssuer() != null) {
issuerNames = createGeneralNameList(aki.getAuthorityCertIssuer());
}
Integer issuerSerial = null;
if (aki.getAuthorityCertSerialNumber() != null) {
issuerSerial = aki.getAuthorityCertSerialNumber().intValue();
}
return new AuthorityKeyIdentifier(keyIdentifier, issuerNames,
issuerSerial);
}
示例11: decode
import org.bouncycastle.asn1.DEREncodable; //导入依赖的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);
}
}
示例12: getBasicConstraints
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
/**
* Creates a <code>BasicConstraints</code> object from given
* extension.
*
* @param ext the extension.
* @return the <code>BasicConstraints</code> object.
* @exception IOException if something fails.
*/
public static BasicConstraints getBasicConstraints(X509Extension ext)
throws IOException {
DERObject obj = BouncyCastleUtil.getExtensionObject(ext);
if (obj instanceof ASN1Sequence) {
ASN1Sequence seq = (ASN1Sequence)obj;
int size = seq.size();
if (size == 0) {
return new BasicConstraints(false);
} else if (size == 1) {
DEREncodable value = seq.getObjectAt(0);
if (value instanceof DERInteger) {
int length = ((DERInteger)value).getValue().intValue();
return new BasicConstraints(false, length);
} else if (value instanceof DERBoolean) {
boolean ca = ((DERBoolean)value).isTrue();
return new BasicConstraints(ca);
}
}
}
return BasicConstraints.getInstance(obj);
}
示例13: setBagAttribute
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
public void setBagAttribute(
DERObjectIdentifier oid,
DEREncodable attribute)
{
if (pkcs12Attributes.containsKey(oid))
{ // preserve original ordering
pkcs12Attributes.put(oid, attribute);
}
else
{
pkcs12Attributes.put(oid, attribute);
pkcs12Ordering.addElement(oid);
}
}
示例14: ContentInfo
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
public ContentInfo(
DERObjectIdentifier contentType,
DEREncodable content)
{
this.contentType = contentType;
this.content = content;
}
示例15: dumpAsString
import org.bouncycastle.asn1.DEREncodable; //导入依赖的package包/类
/**
* dump out a DER object as a formatted string
*
* @param obj the DERObject to be dumped out.
*/
public static String dumpAsString(
DEREncodable obj)
{
StringBuffer buf = new StringBuffer();
_dumpAsString("", false, obj.getDERObject(), buf);
return buf.toString();
}