public static X9ECParameters getByName(String name) {
    ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) objIds.get(Strings.toLowerCase(name));

    if (oid != null) {
      return getByOID(oid);
    }

    return null;
  }
  public String toString() {
    StringBuffer buf = new StringBuffer();
    String nl = Strings.lineSeparator();

    buf.append("      userCertificate: ").append(this.getSerialNumber()).append(nl);
    buf.append("       revocationDate: ").append(this.getRevocationDate()).append(nl);
    buf.append("       certificateIssuer: ").append(this.getCertificateIssuer()).append(nl);

    Extensions extensions = c.getExtensions();

    if (extensions != null) {
      Enumeration e = extensions.oids();
      if (e.hasMoreElements()) {
        buf.append("   crlEntryExtensions:").append(nl);

        while (e.hasMoreElements()) {
          ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
          Extension ext = extensions.getExtension(oid);
          if (ext.getExtnValue() != null) {
            byte[] octs = ext.getExtnValue().getOctets();
            ASN1InputStream dIn = new ASN1InputStream(octs);
            buf.append("                       critical(").append(ext.isCritical()).append(") ");
            try {
              if (oid.equals(X509Extension.reasonCode)) {
                buf.append(CRLReason.getInstance(ASN1Enumerated.getInstance(dIn.readObject())))
                    .append(nl);
              } else if (oid.equals(X509Extension.certificateIssuer)) {
                buf.append("Certificate issuer: ")
                    .append(GeneralNames.getInstance(dIn.readObject()))
                    .append(nl);
              } else {
                buf.append(oid.getId());
                buf.append(" value = ").append(ASN1Dump.dumpAsString(dIn.readObject())).append(nl);
              }
            } catch (Exception ex) {
              buf.append(oid.getId());
              buf.append(" value = ").append("*****").append(nl);
            }
          } else {
            buf.append(nl);
          }
        }
      }
    }

    return buf.toString();
  }
Esempio n. 3
0
  protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
    String md = Strings.toUpperCase(mode);

    if (md.equals("NONE") || md.equals("ECB")) {
      return;
    }

    if (md.equals("1")) {
      privateKeyOnly = true;
      publicKeyOnly = false;
      return;
    } else if (md.equals("2")) {
      privateKeyOnly = false;
      publicKeyOnly = true;
      return;
    }

    throw new NoSuchAlgorithmException("can't support mode " + mode);
  }
Esempio n. 4
0
  protected void engineSetPadding(String padding) throws NoSuchPaddingException {
    String pad = Strings.toUpperCase(padding);

    if (pad.equals("NOPADDING")) {
      cipher = new RSABlindedEngine();
    } else if (pad.equals("PKCS1PADDING")) {
      cipher = new PKCS1Encoding(new RSABlindedEngine());
    } else if (pad.equals("ISO9796-1PADDING")) {
      cipher = new ISO9796d1Encoding(new RSABlindedEngine());
    } else if (pad.equals("OAEPWITHMD5ANDMGF1PADDING")) {
      initFromSpec(
          new OAEPParameterSpec(
              "MD5", "MGF1", new MGF1ParameterSpec("MD5"), PSource.PSpecified.DEFAULT));
    } else if (pad.equals("OAEPPADDING")) {
      initFromSpec(OAEPParameterSpec.DEFAULT);
    } else if (pad.equals("OAEPWITHSHA1ANDMGF1PADDING")
        || pad.equals("OAEPWITHSHA-1ANDMGF1PADDING")) {
      initFromSpec(OAEPParameterSpec.DEFAULT);
    } else if (pad.equals("OAEPWITHSHA224ANDMGF1PADDING")
        || pad.equals("OAEPWITHSHA-224ANDMGF1PADDING")) {
      initFromSpec(
          new OAEPParameterSpec(
              "SHA-224", "MGF1", new MGF1ParameterSpec("SHA-224"), PSource.PSpecified.DEFAULT));
    } else if (pad.equals("OAEPWITHSHA256ANDMGF1PADDING")
        || pad.equals("OAEPWITHSHA-256ANDMGF1PADDING")) {
      initFromSpec(
          new OAEPParameterSpec(
              "SHA-256", "MGF1", MGF1ParameterSpec.SHA256, PSource.PSpecified.DEFAULT));
    } else if (pad.equals("OAEPWITHSHA384ANDMGF1PADDING")
        || pad.equals("OAEPWITHSHA-384ANDMGF1PADDING")) {
      initFromSpec(
          new OAEPParameterSpec(
              "SHA-384", "MGF1", MGF1ParameterSpec.SHA384, PSource.PSpecified.DEFAULT));
    } else if (pad.equals("OAEPWITHSHA512ANDMGF1PADDING")
        || pad.equals("OAEPWITHSHA-512ANDMGF1PADDING")) {
      initFromSpec(
          new OAEPParameterSpec(
              "SHA-512", "MGF1", MGF1ParameterSpec.SHA512, PSource.PSpecified.DEFAULT));
    } else {
      throw new NoSuchPaddingException(padding + " unavailable with RSA.");
    }
  }
  public String toString() {
    StringBuffer buf = new StringBuffer();
    String nl = Strings.lineSeparator();

    buf.append("  [0]         Version: ").append(this.getVersion()).append(nl);
    buf.append("         SerialNumber: ").append(this.getSerialNumber()).append(nl);
    buf.append("             IssuerDN: ").append(this.getIssuerDN()).append(nl);
    buf.append("           Start Date: ").append(this.getNotBefore()).append(nl);
    buf.append("           Final Date: ").append(this.getNotAfter()).append(nl);
    buf.append("            SubjectDN: ").append(this.getSubjectDN()).append(nl);
    buf.append("           Public Key: ").append(this.getPublicKey()).append(nl);
    buf.append("  Signature Algorithm: ").append(this.getSigAlgName()).append(nl);

    byte[] sig = this.getSignature();

    buf.append("            Signature: ").append(new String(Hex.encode(sig, 0, 20))).append(nl);
    for (int i = 20; i < sig.length; i += 20) {
      if (i < sig.length - 20) {
        buf.append("                       ").append(new String(Hex.encode(sig, i, 20))).append(nl);
      } else {
        buf.append("                       ")
            .append(new String(Hex.encode(sig, i, sig.length - i)))
            .append(nl);
      }
    }

    Extensions extensions = c.getTBSCertificate().getExtensions();

    if (extensions != null) {
      Enumeration e = extensions.oids();

      if (e.hasMoreElements()) {
        buf.append("       Extensions: \n");
      }

      while (e.hasMoreElements()) {
        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
        Extension ext = extensions.getExtension(oid);

        if (ext.getExtnValue() != null) {
          byte[] octs = ext.getExtnValue().getOctets();
          ASN1InputStream dIn = new ASN1InputStream(octs);
          buf.append("                       critical(").append(ext.isCritical()).append(") ");
          try {
            if (oid.equals(Extension.basicConstraints)) {
              buf.append(BasicConstraints.getInstance(dIn.readObject())).append(nl);
            } else if (oid.equals(Extension.keyUsage)) {
              buf.append(KeyUsage.getInstance(dIn.readObject())).append(nl);
            } else if (oid.equals(MiscObjectIdentifiers.netscapeCertType)) {
              buf.append(new NetscapeCertType((DERBitString) dIn.readObject())).append(nl);
            } else if (oid.equals(MiscObjectIdentifiers.netscapeRevocationURL)) {
              buf.append(new NetscapeRevocationURL((DERIA5String) dIn.readObject())).append(nl);
            } else if (oid.equals(MiscObjectIdentifiers.verisignCzagExtension)) {
              buf.append(new VerisignCzagExtension((DERIA5String) dIn.readObject())).append(nl);
            } else {
              buf.append(oid.getId());
              buf.append(" value = ").append(ASN1Dump.dumpAsString(dIn.readObject())).append(nl);
              // buf.append(" value = ").append("*****").append(nl);
            }
          } catch (Exception ex) {
            buf.append(oid.getId());
            //     buf.append(" value = ").append(new
            // String(Hex.encode(ext.getExtnValue().getOctets()))).append(nl);
            buf.append(" value = ").append("*****").append(nl);
          }
        } else {
          buf.append(nl);
        }
      }
    }

    return buf.toString();
  }
 /**
  * return the object identifier signified by the passed in name. Null if there is no object
  * identifier associated with name.
  *
  * @return the object identifier associated with name, if present.
  */
 public static ASN1ObjectIdentifier getOID(String name) {
   return (ASN1ObjectIdentifier) objIds.get(Strings.toLowerCase(name));
 }