<p>Given a textual message, returns a byte buffer formatted as follows:</p>
<p>{@code [24] "Bitcoin Signed Message:\n" [message.length as a varint] message}</p>
359758
private static byte[] formatMessageForSigning(String message) {
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bos.write(BITCOIN_SIGNED_MESSAGE_HEADER_BYTES.length);
            bos.write(BITCOIN_SIGNED_MESSAGE_HEADER_BYTES);
            byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8);
            VarInt size = new VarInt(messageBytes.length);
            bos.write(size.encode());
            bos.write(messageBytes);
            return bos.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException(e);  // Cannot happen.
        }
    }
477950
private int getByte(int position) {
    if (position + 1 >= length) {
      throw new IllegalStateException("Malformed DN: " + dn);
    }

    int b1, b2;

    b1 = chars[position];
    if (b1 >= '0' && b1 <= '9') {
      b1 = b1 - '0';
    } else if (b1 >= 'a' && b1 <= 'f') {
      b1 = b1 - 87; // 87 = 'a' - 10
    } else if (b1 >= 'A' && b1 <= 'F') {
      b1 = b1 - 55; // 55 = 'A' - 10
    } else {
      throw new IllegalStateException("Malformed DN: " + dn);
    }

    b2 = chars[position + 1];
    if (b2 >= '0' && b2 <= '9') {
      b2 = b2 - '0';
    } else if (b2 >= 'a' && b2 <= 'f') {
      b2 = b2 - 87; // 87 = 'a' - 10
    } else if (b2 >= 'A' && b2 <= 'F') {
      b2 = b2 - 55; // 55 = 'A' - 10
    } else {
      throw new IllegalStateException("Malformed DN: " + dn);
    }

    return (b1 << 4) + b2;
  }
418864
public static String readAscii(final BitInput bitInput, final int lengthSize) throws IOException {
        return new String(readBytes(bitInput, lengthSize, true, 7), "ASCII");
    }
205674
public BEValue bdecodeBytes() throws IOException {
    int c = this.getNextIndicator();
    int num = c - '0';
    if (num < 0 || num > 9)
      throw new InvalidBEncodingException("Number expected, not '"
              + (char) c + "'");
    this.indicator = 0;

    c = this.read();
    int i = c - '0';
    while (i >= 0 && i <= 9) {
      // This can overflow!
      num = num * 10 + i;
      c = this.read();
      i = c - '0';
    }

    if (c != ':') {
      throw new InvalidBEncodingException("Colon expected, not '" +
              (char) c + "'");
    }

    return new BEValue(read(num));
  }
1163686
@SuppressWarnings("PMD.AvoidArrayLoops")
    private static byte[] salt(final byte[] text) {
        final byte size = (byte) CcSalted.RND.nextInt(Tv.TEN);
        final byte[] output = new byte[text.length + (int) size + 2];
        output[0] = size;
        byte sum = (byte) 0;
        for (int idx = 0; idx < (int) size; ++idx) {
            output[idx + 1] = (byte) CcSalted.RND.nextInt();
            sum += output[idx + 1];
        }
        System.arraycopy(text, 0, output, (int) size + 1, text.length);
        output[output.length - 1] = sum;
        return output;
    }
476052
public String digest(String message) {
		final byte[] messageAsByteArray;

		try {
			messageAsByteArray = message.getBytes(charsetName);
		} catch (UnsupportedEncodingException e) {
			throw new DigestException("error converting message to byte array: charsetName=" + charsetName, e);
		}

		final byte[] digest = digest(messageAsByteArray);

		switch (outputMode) {
			case BASE64:
				return Base64.encodeBase64String(digest);
			case HEX:
				return Hex.encodeHexString(digest);
			default:
				return null;
		}
	}
8283
public static ByteBuffer encode(byte[] input) {
		int pos = input.length + input.length / 3;
		if (pos < 64) pos = 64;
		byte[] out = new byte[pos];
		pos = 0;
		int lineCount = 0;
		for (int i = 0; i < input.length; ++i) {
			byte b = input[i];
			if ((b >= 33 && b <= 60) || (b >= 62 && b <= 126) || ((b == 9 || b == 32) && lineCount < 73 && i < input.length - 1)) {
				if (lineCount == 73) {
					if (pos >= out.length - 4)
						out = increaseBuffer(out, pos);
					out[pos++] = '=';
					out[pos++] = '\r';
					out[pos++] = '\n';
					lineCount = 0;
				} else
					if (pos >= out.length - 1)
						out = increaseBuffer(out, pos);
				out[pos++] = b;
				lineCount++;
				continue;
			}
			// need to encode
			if (lineCount >= 73 - (i < input.length - 1 ? 1 : 0)) {
				if (pos >= out.length - 7)
					out = increaseBuffer(out, pos);
				out[pos++] = '=';
				out[pos++] = '\r';
				out[pos++] = '\n';
				lineCount = 0;
			}
			if (pos >= out.length - 3)
				out = increaseBuffer(out, pos);
			out[pos++] = '=';
			out[pos++] = (byte)StringUtil.encodeHexaDigit((b & 0xF0) >> 4);
			out[pos++] = (byte)StringUtil.encodeHexaDigit(b & 0xF);
			lineCount += 3;
		}
		return ByteBuffer.wrap(out, 0, pos);
	}
1107829
public static ByteBuffer bytes(String s)
	    {
	    	if(s==null)
	    		return null;
	        return ByteBuffer.wrap(s.getBytes(UTF_8));
	    }
233527
byte[] readSignResponse() throws IOException {
    // Read the first 9 bytes from the InputStream which are the SSH2_AGENT_SIGN_RESPONSE headers.
    final byte[] headerBytes = readBytes(9, "SSH2_AGENT_SIGN_RESPONSE");
    log.debug("Received SSH2_AGENT_SIGN_RESPONSE message from ssh-agent.");
    final SignResponseHeaders headers = SignResponseHeaders.from(headerBytes);

    // Read the rest of the SSH2_AGENT_SIGN_RESPONSE message from ssh-agent.
    // 5 is the sum of the number of bytes of response code and response length
    final byte[] bytes = readBytes(headers.getLength() - 5);
    final ByteIterator iterator = new ByteIterator(bytes);
    final byte[] responseType = iterator.next();

    final String signatureFormatId = new String(responseType);
    if (!signatureFormatId.equals(Rsa.RSA_LABEL)) {
      throw new RuntimeException("I unexpectedly got a non-Rsa signature format ID in the "
                                 + "SSH2_AGENT_SIGN_RESPONSE's signature blob.");
    }

    return iterator.next();
  }
325555
function bytesToWords(bytes) {
	var bytes_count = bytes.length,
	    bits_count = bytes_count << 3,
	    words = new Uint32Array((bytes_count + 64) >>> 6 << 4);
	for (var i = 0, n = bytes.length; i < n; ++i)
		words[i >>> 2] |= bytes.charCodeAt(i) << ((i & 3) << 3);
	words[bytes_count >> 2] |= 0x80 << (bits_count & 31); // append "1" bit to message
	words[words.length - 2] = bits_count;
	return words;
}
813147
protected String formatByteBuf(String eventName, ByteBuf msg) {
    int length = msg.readableBytes();
    if (length == 0) {
      StringBuilder buf = new StringBuilder(eventName.length() + 4);
      buf.append(eventName).append(": 0B");
      return buf.toString();
    } else {
      return "\n" + MessageUtil.humanize(msg);
    }
  }
42958
public static byte[] textToNumericFormatV4(String src)
    {
        if (src.length() == 0) {
            return null;
        }

        byte[] res = new byte[INADDR4SZ];
        String[] s = src.split("\\.", -1);
        long val;
        try {
            switch(s.length) {
            // BEGIN Android-removed
            /*
            case 1:
                // When only one part is given, the value is stored directly in
                // the network address without any byte rearrangement.

                val = Long.parseLong(s[0]);
                if (val < 0 || val > 0xffffffffL)
                    return null;
                res[0] = (byte) ((val >> 24) & 0xff);
                res[1] = (byte) (((val & 0xffffff) >> 16) & 0xff);
                res[2] = (byte) (((val & 0xffff) >> 8) & 0xff);
                res[3] = (byte) (val & 0xff);
                break;
            case 2:
                // When a two part address is supplied, the last part is
                // interpreted as a 24-bit quantity and placed in the right
                // most three bytes of the network address. This makes the
                // two part address format convenient for specifying Class A
                // network addresses as net.host.

                val = Integer.parseInt(s[0]);
                if (val < 0 || val > 0xff)
                    return null;
                res[0] = (byte) (val & 0xff);
                val = Integer.parseInt(s[1]);
                if (val < 0 || val > 0xffffff)
                    return null;
                res[1] = (byte) ((val >> 16) & 0xff);
                res[2] = (byte) (((val & 0xffff) >> 8) &0xff);
                res[3] = (byte) (val & 0xff);
                break;
            case 3:
                //
                // When a three part address is specified, the last part is
                // interpreted as a 16-bit quantity and placed in the right
                // most two bytes of the network address. This makes the
                // three part address format convenient for specifying
                // Class B net- work addresses as 128.net.host.
                for (int i = 0; i < 2; i++) {
                    val = Integer.parseInt(s[i]);
                    if (val < 0 || val > 0xff)
                        return null;
                    res[i] = (byte) (val & 0xff);
                }
                val = Integer.parseInt(s[2]);
                if (val < 0 || val > 0xffff)
                    return null;
                res[2] = (byte) ((val >> 8) & 0xff);
                res[3] = (byte) (val & 0xff);
                break;
            */
            // END Android-removed
            case 4:
                /*
                 * When four parts are specified, each is interpreted as a
                 * byte of data and assigned, from left to right, to the
                 * four bytes of an IPv4 address.
                 */
                for (int i = 0; i < 4; i++) {
                    val = Integer.parseInt(s[i]);
                    if (val < 0 || val > 0xff)
                        return null;
                    res[i] = (byte) (val & 0xff);
                }
                break;
            default:
                return null;
            }
        } catch(NumberFormatException e) {
            return null;
        }
        return res;
    }
634420
public static Bytes toBytes(Text t) {
    return Bytes.of(t.getBytes(), 0, t.getLength());
  }
796869
public long expectSigned(int bytes) throws IOException {
        switch (bytes) {
            case 8:
                return expectLong();
            case 4:
                return expectInt();
            case 2:
                return expectShort();
            case 1:
                return expectByte();
        }
        throw new IllegalArgumentException("Unsupported byte count for signed: " + bytes);
    }
1184946
public static int bitLength (byte[] bytes) {
        Objects.requireNonNull(bytes, Required.BYTES.toString());
        int byteLength = bytes.length;
        
        int length = 0;
        if (byteLength <= MAX_BYTE_LENGTH && byteLength > 0) {
            length = byteLength * BYTES;
        }
        
        return length;
    }
396415
public long readRawVarint64() throws IOException {
    int shift = 0;
    long result = 0;
    while (shift < 64) {
      final byte b = readRawByte();
      result |= (long)(b & 0x7F) << shift;
      if ((b & 0x80) == 0) {
        return result;
      }
      shift += 7;
    }
    throw InvalidProtocolBufferException.malformedVarint();
  }
806125
@Override
    public String sign(String message) {
        return sign(message, secret.getBytes(Charsets.UTF_8));
    }