EncryptedContentInfo.java
上传用户:lior1029
上传日期:2013-05-07
资源大小:209k
文件大小:3k
源码类别:

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.cms;
  2. import org.bouncycastle.asn1.ASN1OctetString;
  3. import org.bouncycastle.asn1.ASN1Sequence;
  4. import org.bouncycastle.asn1.ASN1TaggedObject;
  5. import org.bouncycastle.asn1.BERSequence;
  6. import org.bouncycastle.asn1.BERTaggedObject;
  7. import org.bouncycastle.asn1.DERObject;
  8. import org.bouncycastle.asn1.DERObjectIdentifier;
  9. import org.bouncycastle.asn1.DEREncodable;
  10. import org.bouncycastle.asn1.ASN1EncodableVector;
  11. import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
  12. public class EncryptedContentInfo
  13.     implements DEREncodable
  14. {
  15. private DERObjectIdentifier contentType;
  16. private AlgorithmIdentifier contentEncryptionAlgorithm;
  17. private ASN1OctetString     encryptedContent;
  18. public EncryptedContentInfo(
  19.         DERObjectIdentifier contentType, 
  20.         AlgorithmIdentifier contentEncryptionAlgorithm,
  21.         ASN1OctetString     encryptedContent)
  22.     {
  23. this.contentType = contentType;
  24. this.contentEncryptionAlgorithm = contentEncryptionAlgorithm;
  25. this.encryptedContent = encryptedContent;
  26. }
  27. public EncryptedContentInfo(
  28.         ASN1Sequence seq)
  29.     {
  30. contentType = (DERObjectIdentifier)seq.getObjectAt(0);
  31. contentEncryptionAlgorithm = AlgorithmIdentifier.getInstance(
  32.                                                         seq.getObjectAt(1));
  33. if (seq.size() > 2)
  34.         {
  35. encryptedContent = ASN1OctetString.getInstance(
  36.                                 (ASN1TaggedObject)seq.getObjectAt(2), false);
  37. }
  38. }
  39.     /**
  40.      * return an EncryptedContentInfo object from the given object.
  41.      *
  42.      * @param obj the object we want converted.
  43.      * @exception IllegalArgumentException if the object cannot be converted.
  44.      */
  45. public static EncryptedContentInfo getInstance(
  46.         Object obj)
  47.     {
  48. if (obj == null || obj instanceof EncryptedContentInfo)
  49.         {
  50. return (EncryptedContentInfo)obj;
  51. }
  52. if (obj instanceof ASN1Sequence)
  53.         {
  54. return new EncryptedContentInfo((ASN1Sequence)obj);
  55. }
  56. throw new IllegalArgumentException("Invalid EncryptedContentInfo: "
  57.                                                 + obj.getClass().getName());
  58. }
  59. public DERObjectIdentifier getContentType()
  60.     {
  61. return contentType;
  62. }
  63. public AlgorithmIdentifier getContentEncryptionAlgorithm()
  64.     {
  65. return contentEncryptionAlgorithm;
  66. }
  67. public ASN1OctetString getEncryptedContent()
  68.     {
  69. return encryptedContent;
  70. }
  71.     /** 
  72.      * <pre>
  73.      * EncryptedContentInfo ::= SEQUENCE {
  74.      *  contentType ContentType,
  75.      *  contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,
  76.      *  encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL 
  77.      * }
  78.      * </pre>
  79.      */
  80. public DERObject getDERObject()
  81.     {
  82.         ASN1EncodableVector  v = new ASN1EncodableVector();
  83. v.add(contentType);
  84. v.add(contentEncryptionAlgorithm);
  85. if (encryptedContent != null)
  86.         {
  87. v.add(new BERTaggedObject(false, 0, encryptedContent));
  88. }
  89. return new BERSequence(v);
  90. }
  91. }