org.spongycastle.asn1.ASN1OctetString类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(230)

本文整理了Java中org.spongycastle.asn1.ASN1OctetString类的一些代码示例,展示了ASN1OctetString类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ASN1OctetString类的具体详情如下:
包路径:org.spongycastle.asn1.ASN1OctetString
类名称:ASN1OctetString

ASN1OctetString介绍

[英]Abstract base for the ASN.1 OCTET STRING data type

This supports BER, and DER forms of the data.

DER form is always primitive single OCTET STRING, while BER support includes the constructed forms.

X.690

8: Basic encoding rules

8.7 Encoding of an octetstring value

8.7.1 The encoding of an octetstring value shall be either primitive or constructed at the option of the sender.
NOTE — Where it is necessary to transfer part of an octet string before the entire OCTET STRING is available, the constructed encoding is used.

8.7.2 The primitive encoding contains zero, one or more contents octets equal in value to the octets in the data value, in the order they appear in the data value, and with the most significant bit of an octet of the data value aligned with the most significant bit of an octet of the contents octets.

8.7.3 The contents octets for the constructed encoding shall consist of zero, one, or more encodings.
NOTE — Each such encoding includes identifier, length, and contents octets, and may include end-of-contents octets if it is constructed.

8.7.3.1 To encode an octetstring value in this way, it is segmented. Each segment shall consist of a series of consecutive octets of the value. There shall be no significance placed on the segment boundaries.
NOTE — A segment may be of size zero, i.e. contain no octets.

8.7.3.2 Each encoding in the contents octets shall represent a segment of the overall octetstring, the encoding arising from a recursive application of this subclause. In this recursive application, each segment is treated as if it were a octetstring value. The encodings of the segments shall appear in the contents octets in the order in which their octets appear in the overall value.
NOTE 1 — As a consequence of this recursion, each encoding in the contents octets may itself be primitive or constructed. However, such encodings will usually be primitive.
NOTE 2 — In particular, the tags in the contents octets are always universal class, number 4.

9: Canonical encoding rules

9.1 Length forms

If the encoding is constructed, it shall employ the indefinite-length form. If the encoding is primitive, it shall include the fewest length octets necessary. [Contrast with 8.1.3.2 b).]

9.2 String encoding forms

BIT STRING, OCTET STRING,and restricted character string values shall be encoded with a primitive encoding if they would require no more than 1000 contents octets, and as a constructed encoding otherwise. The string fragments contained in the constructed encoding shall be encoded with a primitive encoding. The encoding of each fragment, except possibly the last, shall have 1000 contents octets. (Contrast with 8.21.6.)

10: Distinguished encoding rules

10.1 Length forms The definite form of length encoding shall be used, encoded in the minimum number of octets. [Contrast with 8.1.3.2 b).]

10.2 String encoding forms For BIT STRING, OCTET STRING and restricted character string types, the constructed form of encoding shall not be used. (Contrast with 8.21.6.)
[中]ASN的抽象基础。1八位字符串数据类型
这支持BER和DER形式的数据。
DER形式始终是原始的单八进制字符串,而BER支持包括构造的形式。
X.690
8:基本编码规则
8.7八位字符串值的编码
8.7.1八位字符串值的编码应为原始编码或由发送方选择构造。
注-如果需要在整个八位字节字符串可用之前传输八位字节字符串的一部分,则使用构造的编码。
8.7.2原语编码包含零个、一个或多个内容八位字节,其值等于数据值中的八位字节,顺序与它们在数据值中出现的顺序相同,并且数据值的八位字节的最高有效位与内容八位字节的八位字节的最高有效位对齐。
8.7.3构造编码的内容八位字节应包括零个、一个或多个编码。
注-每种编码都包括标识符、长度和内容八位字节,如果构造的话,还可能包括内容结尾八位字节。
8.7.3.1为了以这种方式对八进制字符串值进行编码,将其分段。每个段应由一系列连续的八位字节组成。管段边界上不应有任何意义。
注-段的大小可能为零,即不包含八位字节。
8.7.3.2内容八位字节中的每个编码应代表整个八位字节字符串的一段,该编码源于本款的递归应用。在这个递归应用程序中,每个段都被视为一个八进制字符串值。段的编码应按照其八位字节在总值中的出现顺序出现在内容八位字节中。
注1-作为这种递归的结果,内容八位字节中的每个编码本身可能是原始的或构造的。然而,这种编码通常是原始的。
注2——特别是,内容八位字节中的标签始终是通用类,编号4。
9:规范编码规则
9.1长度表格
如果构造了编码,则应采用不定长形式。如果编码为原始编码,则应包含所需的最小长度的八位字节。[与8.1.3.2 b相比。]
9.2字符串编码形式
如果位字符串、八位字节字符串和受限字符串值不需要超过1000个内容八位字节,则应使用基本编码进行编码,否则应使用构造编码。构造编码中包含的字符串片段应采用原语编码。除最后一个片段外,每个片段的编码应包含1000个内容八位字节。(与8.21.6相比。)
10:区分编码规则
10.1长度形式应使用长度编码的确定形式,以最小八位字节数编码。[与8.1.3.2 b相比。]
10.2字符串编码形式对于位字符串、八位字符串和受限字符串类型,不得使用构造的编码形式。(与8.21.6相比。)

代码示例

代码示例来源:origin: com.itextpdf/itextg

/**
 * Gets a String from an ASN1Primitive
 * @param names    the ASN1Primitive
 * @return    a human-readable String
 * @throws IOException
 */
private static String getStringFromGeneralName(ASN1Primitive names) throws IOException {
  ASN1TaggedObject taggedObject = (ASN1TaggedObject) names ;
  return new String(ASN1OctetString.getInstance(taggedObject, false).getOctets(), "ISO-8859-1");
}

代码示例来源:origin: com.madgag.spongycastle/core

public byte[] getDigest()
  {
    return digest.getOctets();
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

public ASN1Encodable getId()
{
  if (id instanceof ASN1TaggedObject)
  {
    return ASN1OctetString.getInstance((ASN1TaggedObject)id, false);
  }
  return id;
}

代码示例来源:origin: com.madgag.spongycastle/prov

public byte[] getExtensionValue(String oid)
{
  Extension ext = getExtension(new ASN1ObjectIdentifier(oid));
  if (ext != null)
  {
    try
    {
      return ext.getExtnValue().getEncoded();
    }
    catch (Exception e)
    {
      throw new RuntimeException("error encoding " + e.toString());
    }
  }
  return null;
}

代码示例来源:origin: com.madgag/sc-light-jdk15on

public boolean equals(
  Object  o)
{
  if (!(o instanceof X509Extension))
  {
    return false;
  }
  X509Extension   other = (X509Extension)o;
  return other.getValue().equals(this.getValue())
    && (other.isCritical() == this.isCritical());
}

代码示例来源:origin: com.madgag.spongycastle/pkix

/**
 * Return the uncompressed content.
 *
 * @param expanderProvider a provider of expander algorithm implementations.
 * @return the uncompressed content
 * @throws CMSException if there is an exception un-compressing the data.
 */
public byte[] getContent(InputExpanderProvider expanderProvider)
  throws CMSException
{
  ContentInfo     content = comData.getEncapContentInfo();
  ASN1OctetString bytes = (ASN1OctetString)content.getContent();
  InputExpander   expander = expanderProvider.get(comData.getCompressionAlgorithmIdentifier());
  InputStream     zIn = expander.getInputStream(bytes.getOctetStream());
  try
  {
    return CMSUtils.streamToByteArray(zIn);
  }
  catch (IOException e)
  {
    throw new CMSException("exception reading compressed stream.", e);
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

public String toString()
  {
    return ("AuthorityKeyIdentifier: KeyID(" + this.keyidentifier.getOctets() + ")");
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

public static SubjectKeyIdentifier getInstance(
  ASN1TaggedObject obj,
  boolean          explicit)
{
  return getInstance(ASN1OctetString.getInstance(obj, explicit));
}

代码示例来源:origin: com.madgag.spongycastle/prov

public byte[] getExtensionValue(String oid)
{
  Extension ext = getExtension(new ASN1ObjectIdentifier(oid));
  if (ext != null)
  {
    try
    {
      return ext.getExtnValue().getEncoded();
    }
    catch (Exception e)
    {
      throw new IllegalStateException("Exception encoding: " + e.toString());
    }
  }
  return null;
}

代码示例来源:origin: com.madgag.spongycastle/core

public boolean equals(
  Object  o)
{
  if (!(o instanceof X509Extension))
  {
    return false;
  }
  X509Extension   other = (X509Extension)o;
  return other.getValue().equals(this.getValue())
    && (other.isCritical() == this.isCritical());
}

代码示例来源:origin: com.madgag.spongycastle/bcpkix-jdk15on

/**
 * Return the uncompressed content.
 *
 * @param expanderProvider a provider of expander algorithm implementations.
 * @return the uncompressed content
 * @throws CMSException if there is an exception un-compressing the data.
 */
public byte[] getContent(InputExpanderProvider expanderProvider)
  throws CMSException
{
  ContentInfo     content = comData.getEncapContentInfo();
  ASN1OctetString bytes = (ASN1OctetString)content.getContent();
  InputExpander   expander = expanderProvider.get(comData.getCompressionAlgorithmIdentifier());
  InputStream     zIn = expander.getInputStream(bytes.getOctetStream());
  try
  {
    return CMSUtils.streamToByteArray(zIn);
  }
  catch (IOException e)
  {
    throw new CMSException("exception reading compressed stream.", e);
  }
}

代码示例来源:origin: com.madgag.spongycastle/pkix

/**
 * Return the ASN.1 object contained in a byte[] returned by a getExtensionValue() call.
 *
 * @param encExtValue DER encoded OCTET STRING containing the DER encoded extension object.
 * @return an ASN.1 object
 * @throws java.io.IOException on a parsing error.
 */
public static ASN1Primitive parseExtensionValue(byte[] encExtValue)
  throws IOException
{
  return ASN1Primitive.fromByteArray(ASN1OctetString.getInstance(encExtValue).getOctets());
}

代码示例来源:origin: com.madgag.spongycastle/core

public byte[] getKeyHash()
{
  if (this.value instanceof ASN1OctetString)
  {
    ASN1OctetString octetString = (ASN1OctetString)this.value;
    return octetString.getOctets();
  }
  return null;
}

代码示例来源:origin: com.madgag/sc-light-jdk15on

public static ContentIdentifier getInstance(Object o)
{
  if (o instanceof ContentIdentifier)
  {
    return (ContentIdentifier) o;
  }
  else if (o != null)
  {
    return new ContentIdentifier(ASN1OctetString.getInstance(o));
  }
  return null;
}

代码示例来源:origin: com.madgag/scprov-jdk15on

public byte[] getExtensionValue(String oid)
  {
    X509Extensions exts = this.getSingleExtensions();

    if (exts != null)
    {
      X509Extension   ext = exts.getExtension(new DERObjectIdentifier(oid));

      if (ext != null)
      {
        try
        {
          return ext.getValue().getEncoded(ASN1Encoding.DER);
        }
        catch (Exception e)
        {
          throw new RuntimeException("error encoding " + e.toString());
        }
      }
    }

    return null;
  }
}

代码示例来源:origin: com.madgag/sc-light-jdk15on

public boolean equals(
  Object  o)
{
  if (!(o instanceof Extension))
  {
    return false;
  }
  Extension other = (Extension)o;
  return other.getExtnValue().equals(this.getExtnValue())
    && (other.isCritical() == this.isCritical());
}

代码示例来源:origin: com.madgag.spongycastle/bcpkix-jdk15on

static byte[] getSubjectKeyId(X509Certificate cert)
{
  byte[] ext = cert.getExtensionValue(Extension.subjectKeyIdentifier.getId());
  if (ext != null)
  {
    return ASN1OctetString.getInstance(ASN1OctetString.getInstance(ext).getOctets()).getOctets();
  }
  else
  {
    return null;
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

/**
 * Return the salt to use.
 *
 * @return the input salt.
 */
public byte[] getSalt()
{
  return octStr.getOctets();
}

代码示例来源:origin: com.madgag.spongycastle/core

public static DSTU4145PublicKey getInstance(Object obj)
{
  if (obj instanceof DSTU4145PublicKey)
  {
    return (DSTU4145PublicKey)obj;
  }
  if (obj != null)
  {
    return new DSTU4145PublicKey(ASN1OctetString.getInstance(obj));
  }
  return null;
}

代码示例来源:origin: com.madgag/scprov-jdk15on

public byte[] getExtensionValue(String oid)
  {
    X509Extensions exts = this.getSingleRequestExtensions();

    if (exts != null)
    {
      X509Extension   ext = exts.getExtension(new DERObjectIdentifier(oid));

      if (ext != null)
      {
        try
        {
          return ext.getValue().getEncoded(ASN1Encoding.DER);
        }
        catch (Exception e)
        {
          throw new RuntimeException("error encoding " + e.toString());
        }
      }
    }

    return null;
  }
}

相关文章