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