예제 #1
0
  private byte[] encodeObj(DEREncodable obj) throws IOException {
    if (obj != null) {
      return obj.getDERObject().getEncoded();
    }

    return null;
  }
예제 #2
0
  /**
   * Constructor from ASN1Sequence
   *
   * <p>the principal will be a list of constructed sets, each containing an (OID, String) pair.
   */
  public X509Name(ASN1Sequence seq) {
    this.seq = seq;

    Enumeration e = seq.getObjects();

    while (e.hasMoreElements()) {
      ASN1Set set = ASN1Set.getInstance(e.nextElement());

      for (int i = 0; i < set.size(); i++) {
        ASN1Sequence s = ASN1Sequence.getInstance(set.getObjectAt(i));

        if (s.size() != 2) {
          throw new IllegalArgumentException("badly sized pair");
        }

        ordering.addElement(DERObjectIdentifier.getInstance(s.getObjectAt(0)));

        DEREncodable value = s.getObjectAt(1);
        if (value instanceof DERString) {
          values.addElement(((DERString) value).getString());
        } else {
          values.addElement("#" + bytesToString(Hex.encode(value.getDERObject().getDEREncoded())));
        }
        added.addElement((i != 0) ? TRUE : FALSE); // to allow earlier JDK compatibility
      }
    }
  }
  /**
   * return the ASN.1 encoded key derivation algorithm parameters, or null if there aren't any.
   *
   * @return ASN.1 encoding of key derivation algorithm parameters.
   */
  public byte[] getKeyDerivationAlgParams() {
    try {
      if (info.getKeyDerivationAlgorithm() != null) {
        DEREncodable params = info.getKeyDerivationAlgorithm().getParameters();
        if (params != null) {
          return params.getDERObject().getEncoded();
        }
      }

      return null;
    } catch (Exception e) {
      throw new RuntimeException("exception getting encryption parameters " + e);
    }
  }
  /**
   * return an AlgorithmParameters object representing the parameters to the key derivation
   * algorithm to the recipient.
   *
   * @return AlgorithmParameters object, null if there aren't any.
   */
  public AlgorithmParameters getKeyDerivationAlgParameters(Provider provider) {
    try {
      if (info.getKeyDerivationAlgorithm() != null) {
        DEREncodable params = info.getKeyDerivationAlgorithm().getParameters();
        if (params != null) {
          AlgorithmParameters algP =
              AlgorithmParameters.getInstance(
                  info.getKeyDerivationAlgorithm().getObjectId().toString(), provider);

          algP.init(params.getDERObject().getEncoded());

          return algP;
        }
      }

      return null;
    } catch (Exception e) {
      throw new RuntimeException("exception getting encryption parameters " + e);
    }
  }