Convert the given char array into a byte array for use with PBE encryption - CSharp System

CSharp examples for System:Byte Array

Description

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

Demo Code


using System;//from  w  w w.  ja  va2 s .c o m

public class Main{
        /// <summary>
        /// Convert the given char array into a byte array for use with PBE encryption
        /// </summary>
        /// 
        /// <param name="A">The char array</param>
        /// 
        /// <returns>The converted array</returns>
        public static byte[] ToByteArrayForPBE(char[] A)
        {

            byte[] bout = new byte[A.Length];

            for (int i = 0; i < A.Length; i++)
                bout[i] = (byte)A[i];

            int length = bout.Length * 2;
            byte[] ret = new byte[length + 2];
            int j = 0;

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

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

            return ret;
        }
}

Related Tutorials