Java Byte Array Create toByteArrayForPBE(char[] chars)

Here you can find the source of toByteArrayForPBE(char[] chars)

Description

Convert the given char array into a byte array for use with PBE encryption.

License

Open Source License

Parameter

Parameter Description
chars the char array

Return

the converted array

Declaration

public static byte[] toByteArrayForPBE(char[] chars) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from ww  w . j  av a 2s .co m*/
     * Convert the given char array into a
     * byte array for use with PBE encryption.
     *
     * @param chars the char array
     * @return the converted array
     */
    public static byte[] toByteArrayForPBE(char[] chars) {

        byte[] out = new byte[chars.length];

        for (int i = 0; i < chars.length; i++) {
            out[i] = (byte) chars[i];
        }

        int length = out.length * 2;
        byte[] ret = new byte[length + 2];

        int j = 0;
        for (int i = 0; i < out.length; i++) {
            j = i * 2;
            ret[j] = 0;
            ret[j + 1] = out[i];
        }

        ret[length] = 0;
        ret[length + 1] = 0;

        return ret;
    }
}

Related

  1. toByteArray(String uid)
  2. toByteArray(String value)
  3. toByteArray(String[] anArray)
  4. toByteArray1D(int[][] d)
  5. toByteArrayBE(byte b)
  6. toByteArrayFromPositiveInts(int[] inInts)
  7. toByteArrayFromString(String value, int radix)
  8. toByteArrayLE(int value)
  9. toByteArrayMM(int value)