Package org.mozilla.jss.asn1

Examples of org.mozilla.jss.asn1.OBJECT_IDENTIFIER


      byte[] tmp = new byte[2 + (((ECFieldFp) params.getCurve().getField())
          .getFieldSize() + 7) / 8];
      tmp[0] = 0x02;
      tmp[1] = (byte) EcCore.fieldElemToBytes(r, params, tmp, 2);
      seq.addElement(new ANY(tmp));

      tmp = new byte[2 + (((ECFieldFp) params.getCurve().getField())
          .getFieldSize() + 7) / 8];
      tmp[0] = 0x02;
      tmp[1] = (byte) EcCore.fieldElemToBytes(s, params, tmp, 2);
      seq.addElement(new ANY(tmp));

      seq.encode(baos);
    } catch (Exception ex) {
      throw new SignatureException("Internal ASN.1 encoding error", ex);
    }
View Full Code Here


    SEQUENCE algid = new SEQUENCE();
    algid.addElement(new OBJECT_IDENTIFIER("1.2.840.10045.2.1"));
    algid.addElement(new OBJECT_IDENTIFIER(EcCore.getOID(params)));
    outer.addElement(algid);

    BIT_STRING ecPublivKey = new BIT_STRING(EcCore.ecPointToBytes(getW(),
        params), 0);
    outer.addElement(ecPublivKey);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
View Full Code Here

          throw new IllegalArgumentException("Unsupported key");

        ECParameterSpec params = EcCore.getParams(decodeOID(algid
            .getParameters()));

        BIT_STRING bs = (BIT_STRING) ecPublicKey.elementAt(1);
        data = bs.getBits();

        return new EcPublicKeyImpl(EcCore.bytesToECPoint(data, params), params);
      } catch (Exception e) {
        throw new InvalidKeySpecException("Invalid key encoding", e);
      }
View Full Code Here

  @Override
  public byte[] getEncoded() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    SEQUENCE privateKeyInfo = new SEQUENCE();
    privateKeyInfo.addElement(new INTEGER(0));

    SEQUENCE algid = new SEQUENCE();
    algid.addElement(new OBJECT_IDENTIFIER("1.2.840.10045.2.1"));
    algid.addElement(new OBJECT_IDENTIFIER(EcCore.getOID(params)));
    privateKeyInfo.addElement(algid);

    SEQUENCE ecPrivateKey = new SEQUENCE();
    ecPrivateKey.addElement(new INTEGER(1));
    ecPrivateKey
        .addElement(new OCTET_STRING(EcCore.fieldElemToBytes(S, params)));

    try {
      ecPrivateKey.encode(baos);
View Full Code Here

    SEQUENCE privateKeyInfo = new SEQUENCE();
    privateKeyInfo.addElement(new INTEGER(0));

    SEQUENCE algid = new SEQUENCE();
    algid.addElement(new OBJECT_IDENTIFIER("1.2.840.10045.2.1"));
    algid.addElement(new OBJECT_IDENTIFIER(EcCore.getOID(params)));
    privateKeyInfo.addElement(algid);

    SEQUENCE ecPrivateKey = new SEQUENCE();
    ecPrivateKey.addElement(new INTEGER(1));
    ecPrivateKey
View Full Code Here

  @Override
  public byte[] getEncoded() {
    SEQUENCE outer = new SEQUENCE();

    SEQUENCE algid = new SEQUENCE();
    algid.addElement(new OBJECT_IDENTIFIER("1.2.840.10045.2.1"));
    algid.addElement(new OBJECT_IDENTIFIER(EcCore.getOID(params)));
    outer.addElement(algid);

    BIT_STRING ecPublivKey = new BIT_STRING(EcCore.ecPointToBytes(getW(),
        params), 0);
    outer.addElement(ecPublivKey);
View Full Code Here

  // "Translate" e.g. {1 2 840 10045 2 1} to 1.2.840.10045.2.1
  private static String decodeOID(ASN1Value val) throws Exception {
    OBJECT_IDENTIFIER.Template ot = new OBJECT_IDENTIFIER.Template();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    val.encode(baos);
    OBJECT_IDENTIFIER o = (OBJECT_IDENTIFIER) ot
        .decode(new ByteArrayInputStream(baos.toByteArray()));
    StringBuffer sb = new StringBuffer();
    long[] nums = o.getNumbers();
    for (int i = 0; i < nums.length - 1; i++) {
      sb.append(nums[i] + ".");
    }
    sb.append(nums[nums.length - 1]);
    return sb.toString();
View Full Code Here

    privateKeyInfo.addElement(algid);

    SEQUENCE ecPrivateKey = new SEQUENCE();
    ecPrivateKey.addElement(new INTEGER(1));
    ecPrivateKey
        .addElement(new OCTET_STRING(EcCore.fieldElemToBytes(S, params)));

    try {
      ecPrivateKey.encode(baos);
    } catch (IOException ioe) {
      throw new RuntimeException("Internal ASN.1 encoding error", ioe);
    }

    privateKeyInfo.addElement(new OCTET_STRING(baos.toByteArray()));

    baos.reset();
    try {
      privateKeyInfo.encode(baos);
    } catch (IOException ioe) {
View Full Code Here

        foo.addElement(new INTEGER.Template());
        foo.addElement(new OCTET_STRING.Template());

        SEQUENCE ecPrivateKey = (SEQUENCE) foo.decode(new ByteArrayInputStream(
            pki.getEncoded()));
        OCTET_STRING arrhh = (OCTET_STRING) ecPrivateKey.elementAt(1);
        return new EcPrivateKeyImpl(new BigInteger(1, arrhh.toByteArray()),
            params);
      } catch (Exception e) {
        throw new InvalidKeySpecException("Invalid key encoding", e);
      }
    }
View Full Code Here

      // SEQUENCE seq = new SEQUENCE();
      // seq.addElement(new INTEGER(EcCore.fieldElemToBytes(r, params)));
      // seq.addElement(new INTEGER(EcCore.fieldElemToBytes(s, params)));

      // Sigh, another work around...
      SEQUENCE seq = new SEQUENCE();

      byte[] tmp = new byte[2 + (((ECFieldFp) params.getCurve().getField())
          .getFieldSize() + 7) / 8];
      tmp[0] = 0x02;
      tmp[1] = (byte) EcCore.fieldElemToBytes(r, params, tmp, 2);
      seq.addElement(new ANY(tmp));

      tmp = new byte[2 + (((ECFieldFp) params.getCurve().getField())
          .getFieldSize() + 7) / 8];
      tmp[0] = 0x02;
      tmp[1] = (byte) EcCore.fieldElemToBytes(s, params, tmp, 2);
      seq.addElement(new ANY(tmp));

      seq.encode(baos);
    } catch (Exception ex) {
      throw new SignatureException("Internal ASN.1 encoding error", ex);
    }

    return baos.toByteArray();
View Full Code Here

TOP

Related Classes of org.mozilla.jss.asn1.OBJECT_IDENTIFIER

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.