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

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.pkcs;
  2. import java.math.BigInteger;
  3. import org.bouncycastle.asn1.*;
  4. import org.bouncycastle.asn1.x509.*;
  5. public class MacData
  6.     implements DEREncodable
  7. {
  8.     DigestInfo                  digInfo;
  9.     byte[]                      salt;
  10.     BigInteger                  iterationCount;
  11.     public static MacData getInstance(
  12.         Object  obj)
  13.     {
  14.         if (obj instanceof MacData)
  15.         {
  16.             return (MacData)obj;
  17.         }
  18.         else if (obj instanceof ASN1Sequence)
  19.         {
  20.             return new MacData((ASN1Sequence)obj);
  21.         }
  22.         throw new IllegalArgumentException("unknown object in factory");
  23.     }
  24.     public MacData(
  25.         ASN1Sequence seq)
  26.     {
  27.         this.digInfo = DigestInfo.getInstance(seq.getObjectAt(0));
  28.         this.salt = ((ASN1OctetString)seq.getObjectAt(1)).getOctets();
  29.         if (seq.size() == 3)
  30.         {
  31.             this.iterationCount = ((DERInteger)seq.getObjectAt(2)).getValue();
  32.         }
  33.         else
  34.         {
  35.             this.iterationCount = BigInteger.valueOf(1);
  36.         }
  37.     }
  38.     public MacData(
  39.         DigestInfo  digInfo,
  40.         byte[]      salt,
  41.         int         iterationCount)
  42.     {
  43.         this.digInfo = digInfo;
  44.         this.salt = salt;
  45.         this.iterationCount = BigInteger.valueOf(iterationCount);
  46.     }
  47.     public DigestInfo getMac()
  48.     {
  49.         return digInfo;
  50.     }
  51.     public byte[] getSalt()
  52.     {
  53.         return salt;
  54.     }
  55.     public BigInteger getIterationCount()
  56.     {
  57.         return iterationCount;
  58.     }
  59.     public DERObject getDERObject()
  60.     {
  61.         ASN1EncodableVector  v = new ASN1EncodableVector();
  62.         v.add(digInfo);
  63.         v.add(new DEROctetString(salt));
  64.         v.add(new DERInteger(iterationCount));
  65.         return new DERSequence(v);
  66.     }
  67. }