Examples of DERDecoder


Examples of codec.asn1.DERDecoder

  AlgorithmIdentifier aid;
  PBEParameterSpec pspec;
  SecretKeyFactory skf;
  PrivateKeyInfo pki;
  KeyFactory kf;
  DERDecoder dec;
  SecretKey secret;
  KeySpec kspec;
  Cipher cipher;
  String name;
  byte[] buf;

  try {
      name = algorithm_.getAlgorithmOID().toString();
      params = algorithm_.getParameters();
      pspec = (PBEParameterSpec) params
        .getParameterSpec(PBEParameterSpec.class);

      skf = SecretKeyFactory.getInstance(name);
      kspec = new PBEKeySpec(password);
      secret = skf.generateSecret(kspec);

      cipher = Cipher.getInstance(name);
      cipher.init(Cipher.DECRYPT_MODE, secret, pspec);

      buf = cipher.doFinal(encryptedData_.getByteArray());
      kspec = new PKCS8EncodedKeySpec(buf);

      pki = new PrivateKeyInfo();
      dec = new DERDecoder(new ByteArrayInputStream(buf));
      pki.decode(dec);
      dec.close();

      aid = pki.getAlgorithmIdentifier();
      name = aid.getAlgorithmOID().toString();
      kf = KeyFactory.getInstance(name);
View Full Code Here

Examples of codec.asn1.DERDecoder

     */
    public void setPrivateKey(PrivateKey key) throws InvalidKeyException {
  if (key == null)
      throw new NullPointerException("Key is null!");

  DERDecoder dec;

  clear();

  version_ = new ASN1Integer(VERSION);
  add(version_);

  algorithm_ = new AlgorithmIdentifier();
  add(algorithm_);

  encodedKey_ = new ASN1OctetString();
  add(encodedKey_);

  attributes_ = new ASN1SetOf(Attribute.class);
  add(new ASN1TaggedType(0, attributes_, false, true));

  try {
      dec = new DERDecoder(new ByteArrayInputStream(key.getEncoded()));

      decode(dec);
      dec.close();
  } catch (IOException e) {
      throw new InvalidKeyException("Caught IOException!");
  } catch (ASN1Exception e) {
      throw new InvalidKeyException("Bad encoding!");
  }
View Full Code Here

Examples of codec.asn1.DERDecoder

     * encodings.
     *
     * @return The raw key decoded according to DER.
     */
    public ASN1Type getDecodedRawKey() throws CorruptedCodeException {
  DERDecoder dec;
  ASN1Type raw;

  try {
      dec = new DERDecoder(new ByteArrayInputStream(encodedKey_
        .getByteArray()));

      raw = dec.readType();
      dec.close();

      return raw;
  } catch (ASN1Exception e) {
      throw new CorruptedCodeException("Cannot decode raw key!");
  } catch (IOException e) {
View Full Code Here

Examples of codec.asn1.DERDecoder

  this();

  try {
      ByteArrayInputStream bais = new ByteArrayInputStream(enc);

      decode(new DERDecoder(bais));
      bais.close();
  } catch (IOException e) {
      throw new ASN1Exception(e.getMessage());
  }
    }
View Full Code Here

Examples of codec.asn1.DERDecoder

     */
    public CertificationRequest(InputStream in) throws ASN1Exception,
      IOException {
  this();

  DERDecoder dec;

  dec = new DERDecoder(in);
  decode(dec);
  dec.close();
    }
View Full Code Here

Examples of codec.asn1.DERDecoder

  this();

  try {
      ByteArrayInputStream bais = new ByteArrayInputStream(cert);
      decode(new DERDecoder(bais));
      bais.close();
  } catch (Exception e) {
      throw new java.security.cert.CertificateEncodingException(e
        .getMessage());
  }
View Full Code Here

Examples of codec.asn1.DERDecoder

    public X509Certificate(InputStream in)
      throws java.security.cert.CertificateEncodingException {
  this();

  try {
      decode(new DERDecoder(in));
  } catch (Exception e) {
      throw new java.security.cert.CertificateEncodingException(e
        .getMessage());
  }
    }
View Full Code Here

Examples of codec.asn1.DERDecoder

  }
    }

    public void readExternal(ObjectInput s) throws IOException {
  try {
      decode(new DERDecoder((ObjectInputStream) s));
  } catch (ASN1Exception e) {
      throw new RuntimeException(e.toString());
  }
    }
View Full Code Here

Examples of codec.asn1.DERDecoder

  }
    }

    public void readExternal(ObjectInput s) throws IOException {
  try {
      decode(new DERDecoder((ObjectInputStream) s));
  } catch (ASN1Exception e) {
      throw new RuntimeException(e.toString());
  }
    }
View Full Code Here

Examples of codec.asn1.DERDecoder

   * better to just catch it and throw a runtime exception (an error).
   *
   * --volker roth
   */
  ByteArrayInputStream in;
  DERDecoder dec;

  if (b == null) {
      throw new NullPointerException("input array");
  }
  in = new ByteArrayInputStream(b);
  dec = new DERDecoder(in);

  decode(dec);

  /*
   * Let stream free resources.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.