Java ByteBuffer Read readDERString(ByteBuffer buf)

Here you can find the source of readDERString(ByteBuffer buf)

Description

This method reads a DER encoded byte string from a ByteBuffer.

License

Open Source License

Parameter

Parameter Description
buf buffer containing DER encoded bytes.

Return

bytes the decoded bytes.

Declaration

public static byte[] readDERString(ByteBuffer buf) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    /**/*from  www  .ja  v  a 2 s .c  o m*/
     * This method reads a DER encoded byte string from a ByteBuffer.
     *
     * A DER encoded string has
     *
     * length = 4 bytes big-endian integer<br/>
     * string = length bytes
     *
     * @param buf
     *            buffer containing DER encoded bytes.
     * @return bytes the decoded bytes.
     */
    public static byte[] readDERString(ByteBuffer buf) {
        int length = buf.getInt();
        if (length > 8192) {
            throw new IllegalArgumentException("DER String Length " + length + " > 8192");
        }
        byte[] bytes = new byte[length];
        buf.get(bytes);
        return bytes;
    }
}

Related

  1. readByteBufferFromFile(String filepath)
  2. readChars(ByteBuffer bb, int length)
  3. readCharsUTF8(ByteBuffer bb, int length)
  4. readCInt(ByteBuffer buffer)
  5. readCString(ByteBuffer buf, int len)
  6. readDword(ByteBuffer buffer)
  7. readFileToByteBuffer(File file)
  8. readFixedLengthString(ByteBuffer buf, int length)
  9. readFixedLengthString(ByteBuffer byteBuffer, int size)