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

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.cms;
  2. import org.bouncycastle.asn1.ASN1Sequence;
  3. import org.bouncycastle.asn1.ASN1TaggedObject;
  4. import org.bouncycastle.asn1.ASN1OctetString;
  5. import org.bouncycastle.asn1.DERSequence;
  6. import org.bouncycastle.asn1.DEREncodable;
  7. import org.bouncycastle.asn1.DERInteger;
  8. import org.bouncycastle.asn1.DERObject;
  9. import org.bouncycastle.asn1.ASN1EncodableVector;
  10. import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
  11. public class KeyTransRecipientInfo
  12.     implements DEREncodable
  13. {
  14. private DERInteger          version;
  15. private RecipientIdentifier rid;
  16. private AlgorithmIdentifier keyEncryptionAlgorithm;
  17. private ASN1OctetString     encryptedKey;
  18. public KeyTransRecipientInfo(
  19.         RecipientIdentifier rid,
  20.         AlgorithmIdentifier keyEncryptionAlgorithm,
  21.         ASN1OctetString     encryptedKey)
  22.     {
  23. if (rid.getDERObject() instanceof ASN1TaggedObject)
  24.         {
  25.             this.version = new DERInteger(2);
  26. }
  27. else
  28.         {
  29.             this.version = new DERInteger(0);
  30. }
  31.         this.rid = rid;
  32.         this.keyEncryptionAlgorithm = keyEncryptionAlgorithm;
  33.         this.encryptedKey = encryptedKey;
  34. }
  35. public KeyTransRecipientInfo(
  36.         ASN1Sequence seq)
  37.     {
  38. this.version = (DERInteger)seq.getObjectAt(0);
  39. this.rid = RecipientIdentifier.getInstance(seq.getObjectAt(1));
  40. this.keyEncryptionAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(2));
  41. this.encryptedKey = (ASN1OctetString)seq.getObjectAt(3);
  42. }
  43.     /**
  44.      * return a KeyTransRecipientInfo object from the given object.
  45.      *
  46.      * @param obj the object we want converted.
  47.      * @exception IllegalArgumentException if the object cannot be converted.
  48.      */
  49. public static KeyTransRecipientInfo getInstance(
  50.         Object obj)
  51.     {
  52. if (obj == null || obj instanceof KeyTransRecipientInfo)
  53.         {
  54. return (KeyTransRecipientInfo)obj;
  55. }
  56. if(obj instanceof ASN1Sequence)
  57.         {
  58. return new KeyTransRecipientInfo((ASN1Sequence)obj);
  59. }
  60. throw new IllegalArgumentException(
  61.         "Illegal object in KeyTransRecipientInfo: " + obj.getClass().getName());
  62. public DERInteger getVersion()
  63.     {
  64. return version;
  65. }
  66. public RecipientIdentifier getRecipientIdentifier()
  67.     {
  68. return rid;
  69. }
  70. public AlgorithmIdentifier getKeyEncryptionAlgorithm()
  71.     {
  72. return keyEncryptionAlgorithm;
  73. }
  74. public ASN1OctetString getEncryptedKey()
  75.     {
  76. return encryptedKey;
  77. }
  78.     /** 
  79.      * <pre>
  80.      * KeyTransRecipientInfo ::= SEQUENCE {
  81.      *  version CMSVersion,  -- always set to 0 or 2
  82.      *  rid RecipientIdentifier,
  83.      *  keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
  84.      *  encryptedKey EncryptedKey 
  85.      * }
  86.      * </pre>
  87.      */
  88. public DERObject getDERObject()
  89.     {
  90.         ASN1EncodableVector  v = new ASN1EncodableVector();
  91. v.add(version);
  92. v.add(rid);
  93. v.add(keyEncryptionAlgorithm);
  94. v.add(encryptedKey);
  95. return new DERSequence(v);
  96. }
  97. }