Exemplo 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);
      }
    }
  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));
      }
    }
  }
Exemplo n.º 3
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);
      }
    }
  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;
  }
Exemplo n.º 5
0
  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;
  }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
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);
      }
    }
 public static AttributeCertificateInfo getInstance(ASN1TaggedObject obj, boolean explicit) {
   return getInstance(ASN1Sequence.getInstance(obj, explicit));
 }
Exemplo n.º 9
0
 public static PKMACValue getInstance(ASN1TaggedObject obj, boolean isExplicit) {
   return getInstance(ASN1Sequence.getInstance(obj, isExplicit));
 }