Esempio n. 1
0
    public PEMKeyPair parse(byte[] encoding) throws IOException {
      try {
        ASN1Sequence seq = ASN1Sequence.getInstance(encoding);

        if (seq.size() != 9) {
          throw new PEMException("malformed sequence in RSA private key");
        }

        org.mightyfish.asn1.pkcs.RSAPrivateKey keyStruct =
            org.mightyfish.asn1.pkcs.RSAPrivateKey.getInstance(seq);

        RSAPublicKey pubSpec =
            new RSAPublicKey(keyStruct.getModulus(), keyStruct.getPublicExponent());

        AlgorithmIdentifier algId =
            new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE);

        return new PEMKeyPair(
            new SubjectPublicKeyInfo(algId, pubSpec), new PrivateKeyInfo(algId, keyStruct));
      } catch (IOException e) {
        throw e;
      } catch (Exception e) {
        throw new PEMException("problem creating RSA private key: " + e.toString(), e);
      }
    }
  public static AttributeCertificateInfo getInstance(Object obj) {
    if (obj instanceof AttributeCertificateInfo) {
      return (AttributeCertificateInfo) obj;
    } else if (obj != null) {
      return new AttributeCertificateInfo(ASN1Sequence.getInstance(obj));
    }

    return null;
  }
  public static CrlIdentifier getInstance(Object obj) {
    if (obj instanceof CrlIdentifier) {
      return (CrlIdentifier) obj;
    } else if (obj != null) {
      return new CrlIdentifier(ASN1Sequence.getInstance(obj));
    }

    return null;
  }
Esempio n. 4
0
  public static PKMACValue getInstance(Object o) {
    if (o instanceof PKMACValue) {
      return (PKMACValue) o;
    }

    if (o != null) {
      return new PKMACValue(ASN1Sequence.getInstance(o));
    }

    return null;
  }
Esempio n. 5
0
    public PEMKeyPair parse(byte[] encoding) throws IOException {
      try {
        ASN1Sequence seq = ASN1Sequence.getInstance(encoding);

        if (seq.size() != 6) {
          throw new PEMException("malformed sequence in DSA private key");
        }

        //            ASN1Integer              v = (ASN1Integer)seq.getObjectAt(0);
        ASN1Integer p = ASN1Integer.getInstance(seq.getObjectAt(1));
        ASN1Integer q = ASN1Integer.getInstance(seq.getObjectAt(2));
        ASN1Integer g = ASN1Integer.getInstance(seq.getObjectAt(3));
        ASN1Integer y = ASN1Integer.getInstance(seq.getObjectAt(4));
        ASN1Integer x = ASN1Integer.getInstance(seq.getObjectAt(5));

        return new PEMKeyPair(
            new SubjectPublicKeyInfo(
                new AlgorithmIdentifier(
                    X9ObjectIdentifiers.id_dsa,
                    new DSAParameter(p.getValue(), q.getValue(), g.getValue())),
                y),
            new PrivateKeyInfo(
                new AlgorithmIdentifier(
                    X9ObjectIdentifiers.id_dsa,
                    new DSAParameter(p.getValue(), q.getValue(), g.getValue())),
                x));
      } catch (IOException e) {
        throw e;
      } catch (Exception e) {
        throw new PEMException("problem creating DSA private key: " + e.toString(), e);
      }
    }
 private CrlIdentifier(ASN1Sequence seq) {
   if (seq.size() < 2 || seq.size() > 3) {
     throw new IllegalArgumentException();
   }
   this.crlIssuer = X500Name.getInstance(seq.getObjectAt(0));
   this.crlIssuedTime = ASN1UTCTime.getInstance(seq.getObjectAt(1));
   if (seq.size() > 2) {
     this.crlNumber = ASN1Integer.getInstance(seq.getObjectAt(2));
   }
 }
  ECDSAPublicKey(ASN1Sequence seq) throws IllegalArgumentException {
    Enumeration en = seq.getObjects();

    this.usage = ASN1ObjectIdentifier.getInstance(en.nextElement());

    options = 0;
    while (en.hasMoreElements()) {
      Object obj = en.nextElement();

      if (obj instanceof ASN1TaggedObject) {
        ASN1TaggedObject to = (ASN1TaggedObject) obj;
        switch (to.getTagNo()) {
          case 0x1:
            setPrimeModulusP(UnsignedInteger.getInstance(to).getValue());
            break;
          case 0x2:
            setFirstCoefA(UnsignedInteger.getInstance(to).getValue());
            break;
          case 0x3:
            setSecondCoefB(UnsignedInteger.getInstance(to).getValue());
            break;
          case 0x4:
            setBasePointG(ASN1OctetString.getInstance(to, false));
            break;
          case 0x5:
            setOrderOfBasePointR(UnsignedInteger.getInstance(to).getValue());
            break;
          case 0x6:
            setPublicPointY(ASN1OctetString.getInstance(to, false));
            break;
          case 0x7:
            setCofactorF(UnsignedInteger.getInstance(to).getValue());
            break;
          default:
            options = 0;
            throw new IllegalArgumentException("Unknown Object Identifier!");
        }
      } else {
        throw new IllegalArgumentException("Unknown Object Identifier!");
      }
    }
    if (options != 0x20 && options != 0x7F) {
      throw new IllegalArgumentException("All options must be either present or absent!");
    }
  }
Esempio n. 8
0
    public PEMKeyPair parse(byte[] encoding) throws IOException {
      try {
        ASN1Sequence seq = ASN1Sequence.getInstance(encoding);

        org.mightyfish.asn1.sec.ECPrivateKey pKey =
            org.mightyfish.asn1.sec.ECPrivateKey.getInstance(seq);
        AlgorithmIdentifier algId =
            new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, pKey.getParameters());
        PrivateKeyInfo privInfo = new PrivateKeyInfo(algId, pKey);
        SubjectPublicKeyInfo pubInfo =
            new SubjectPublicKeyInfo(algId, pKey.getPublicKey().getBytes());

        return new PEMKeyPair(pubInfo, privInfo);
      } catch (IOException e) {
        throw e;
      } catch (Exception e) {
        throw new PEMException("problem creating EC private key: " + e.toString(), e);
      }
    }
  private AttributeCertificateInfo(ASN1Sequence seq) {
    if (seq.size() < 6 || seq.size() > 9) {
      throw new IllegalArgumentException("Bad sequence size: " + seq.size());
    }

    int start;
    if (seq.getObjectAt(0) instanceof ASN1Integer) // in version 1 certs version is DEFAULT  v1(0)
    {
      this.version = ASN1Integer.getInstance(seq.getObjectAt(0));
      start = 1;
    } else {
      this.version = new ASN1Integer(0);
      start = 0;
    }

    this.holder = Holder.getInstance(seq.getObjectAt(start));
    this.issuer = AttCertIssuer.getInstance(seq.getObjectAt(start + 1));
    this.signature = AlgorithmIdentifier.getInstance(seq.getObjectAt(start + 2));
    this.serialNumber = ASN1Integer.getInstance(seq.getObjectAt(start + 3));
    this.attrCertValidityPeriod = AttCertValidityPeriod.getInstance(seq.getObjectAt(start + 4));
    this.attributes = ASN1Sequence.getInstance(seq.getObjectAt(start + 5));

    for (int i = start + 6; i < seq.size(); i++) {
      ASN1Encodable obj = seq.getObjectAt(i);

      if (obj instanceof DERBitString) {
        this.issuerUniqueID = DERBitString.getInstance(seq.getObjectAt(i));
      } else if (obj instanceof ASN1Sequence || obj instanceof Extensions) {
        this.extensions = Extensions.getInstance(seq.getObjectAt(i));
      }
    }
  }
 public static AttributeCertificateInfo getInstance(ASN1TaggedObject obj, boolean explicit) {
   return getInstance(ASN1Sequence.getInstance(obj, explicit));
 }
Esempio n. 11
0
 public static PKMACValue getInstance(ASN1TaggedObject obj, boolean isExplicit) {
   return getInstance(ASN1Sequence.getInstance(obj, isExplicit));
 }
Esempio n. 12
0
 private PKMACValue(ASN1Sequence seq) {
   algId = AlgorithmIdentifier.getInstance(seq.getObjectAt(0));
   value = DERBitString.getInstance(seq.getObjectAt(1));
 }