Package org.snmp4j.asn1

Examples of org.snmp4j.asn1.BEROutputStream


        AuthenticatedSafe   auth = new AuthenticatedSafe(c);

        bOut.reset();

        BEROutputStream         berOut = new BEROutputStream(bOut);

        berOut.writeObject(auth);

        byte[]              pkg = bOut.toByteArray();

        ContentInfo         mainInfo = new ContentInfo(data, new BERConstructedOctetString(pkg));

        //
        // create the mac
        //
        byte[]                      mSalt = new byte[20];
        int                         itCount = MIN_ITERATIONS;

        random.nextBytes(mSalt);
   
        byte[]  data = ((ASN1OctetString)mainInfo.getContent()).getOctets();

        MacData                 mData;

        try
        {
            Mac                 mac = Mac.getInstance(id_SHA1.getId(), "BC");
            SecretKeyFactory    keyFact = SecretKeyFactory.getInstance(id_SHA1.getId(), "BC");
            PBEParameterSpec    defParams = new PBEParameterSpec(mSalt, itCount);
            PBEKeySpec          pbeSpec = new PBEKeySpec(password);

            mac.init(keyFact.generateSecret(pbeSpec), defParams);

            mac.update(data);

            byte[]      res = mac.doFinal();

            AlgorithmIdentifier     algId = new AlgorithmIdentifier(id_SHA1, new DERNull());
            DigestInfo              dInfo = new DigestInfo(algId, res);

            mData = new MacData(dInfo, mSalt, itCount);
        }
        catch (Exception e)
        {
            throw new IOException("error constructing MAC: " + e.toString());
        }
       
        //
        // output the Pfx
        //
        Pfx                 pfx = new Pfx(mainInfo, mData);

        berOut = new BEROutputStream(stream);

        berOut.writeObject(pfx);
    }
View Full Code Here


        };

        AuthenticatedSafe   auth = new AuthenticatedSafe(info);

        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
        BEROutputStream         berOut = new BEROutputStream(bOut);

        berOut.writeObject(auth);

        byte[]              pkg = bOut.toByteArray();

        ContentInfo         mainInfo = new ContentInfo(data, new BERConstructedOctetString(pkg));

        //
        // create the mac
        //
        byte[]                      mSalt = new byte[20];
        int                         itCount = MIN_ITERATIONS;

        random.nextBytes(mSalt);
   
        byte[]  data = ((ASN1OctetString)mainInfo.getContent()).getOctets();

        MacData                 mData;

        try
        {
            byte[] res = calculatePbeMac(id_SHA1, mSalt, itCount, password, false, data);

            AlgorithmIdentifier     algId = new AlgorithmIdentifier(id_SHA1, new DERNull());
            DigestInfo              dInfo = new DigestInfo(algId, res);

            mData = new MacData(dInfo, mSalt, itCount);
        }
        catch (Exception e)
        {
            throw new IOException("error constructing MAC: " + e.toString());
        }
       
        //
        // output the Pfx
        //
        Pfx                 pfx = new Pfx(mainInfo, mData);

        berOut = new BEROutputStream(stream);

        berOut.writeObject(pfx);
    }
View Full Code Here

                                 Integer32 maxSizeResponseScopedPDU,
                                 StatusInformation statusInformation,
                                 MutableStateReference stateReference)
      throws IOException
  {
    MutableByte mutableByte = new MutableByte();
    int length = BER.decodeHeader(wholeMsg, mutableByte);
    int startPos = (int)wholeMsg.getPosition();
    if (mutableByte.getValue() != BER.SEQUENCE) {
      String txt = "SNMPv1 PDU must start with a SEQUENCE";
      logger.error(txt);
      throw new IOException(txt);
    }
    Integer32 version = new Integer32();
View Full Code Here

  public Null(int exceptionSyntax) {
   setSyntax(exceptionSyntax);
  }

  public void decodeBER(BERInputStream inputStream) throws java.io.IOException {
    MutableByte type = new BER.MutableByte();
    BER.decodeNull(inputStream, type);
    this.syntax = type.getValue() & 0xFF;
  }
View Full Code Here

                                 StatusInformation statusInformation,
                                 MutableStateReference stateReference)
      throws IOException
  {

    MutableByte mutableByte = new MutableByte();
    int length = BER.decodeHeader(wholeMsg, mutableByte);
    int startPos = (int)wholeMsg.getPosition();

    if (mutableByte.getValue() != BER.SEQUENCE) {
      String txt = "SNMPv2c PDU must start with a SEQUENCE";
      logger.error(txt);
      throw new IOException(txt);
    }
    Integer32 version = new Integer32();
View Full Code Here

   * @param inputStream an <code>InputStream</code> containing a BER encoded
   *   byte stream.
   * @throws IOException
   */
  public void decodeBER(BERInputStream inputStream) throws IOException {
    MutableByte mutableByte = new MutableByte();
    int length = BER.decodeHeader(inputStream, mutableByte);
    long startPos = inputStream.getPosition();
    contextEngineID.decodeBER(inputStream);
    contextName.decodeBER(inputStream);
    super.decodeBER(inputStream);
View Full Code Here

                                 StatusInformation statusInformation,
                                 MutableStateReference stateReference)
      throws IOException
  {

    MutableByte mutableByte = new MutableByte();
    int length = BER.decodeHeader(wholeMsg, mutableByte);
    int startPos = (int)wholeMsg.getPosition();

    if (mutableByte.getValue() != BER.SEQUENCE) {
      String txt = "SNMPv2c PDU must start with a SEQUENCE";
      logger.error(txt);
      throw new IOException(txt);
    }
    Integer32 version = new Integer32();
View Full Code Here

  public Null(int exceptionSyntax) {
   setSyntax(exceptionSyntax);
  }

  public void decodeBER(BERInputStream inputStream) throws java.io.IOException {
    MutableByte type = new BER.MutableByte();
    BER.decodeNull(inputStream, type);
    this.syntax = type.getValue() & 0xFF;
  }
View Full Code Here

   * @param inputStream an <code>InputStream</code> containing a BER encoded
   *   byte stream.
   * @throws IOException
   */
  public void decodeBER(BERInputStream inputStream) throws IOException {
    MutableByte mutableByte = new MutableByte();
    int length = BER.decodeHeader(inputStream, mutableByte);
    long startPos = inputStream.getPosition();
    contextEngineID.decodeBER(inputStream);
    contextName.decodeBER(inputStream);
    super.decodeBER(inputStream);
View Full Code Here

                                 Integer32 maxSizeResponseScopedPDU,
                                 StatusInformation statusInformation,
                                 MutableStateReference stateReference)
      throws IOException
  {
    MutableByte mutableByte = new MutableByte();
    int length = BER.decodeHeader(wholeMsg, mutableByte);
    int startPos = (int)wholeMsg.getPosition();
    if (mutableByte.getValue() != BER.SEQUENCE) {
      String txt = "SNMPv1 PDU must start with a SEQUENCE";
      logger.error(txt);
      throw new IOException(txt);
    }
    Integer32 version = new Integer32();
View Full Code Here

TOP

Related Classes of org.snmp4j.asn1.BEROutputStream

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.