}); // the byte 0-255 to be decoded is the index and the value at that position in the array is the byte that is encoded or -1 if this byte encodes nothing public static cByteList Encode(string pString) { if (pString.Length == 0) { return(new cByteList()); } var lBytes = new cByteList(); var lBuffer = new cToBase64Buffer(lBytes); bool lInBase64 = false; foreach (char lChar in pString) { if (lChar < ' ' || lChar > '~') { if (!lInBase64) { lBytes.Add(cASCII.AMPERSAND); lInBase64 = true; } byte[] lCharBytes = BitConverter.GetBytes(lChar); if (BitConverter.IsLittleEndian) { lBuffer.Add(lCharBytes[1]); lBuffer.Add(lCharBytes[0]); } else { lBuffer.Add(lCharBytes[0]); lBuffer.Add(lCharBytes[1]); } } else { if (lInBase64) { lBuffer.Flush(); lBytes.Add(cASCII.HYPEN); lInBase64 = false; } lBytes.Add((byte)lChar); if (lChar == '&') { lBytes.Add(cASCII.HYPEN); } } } if (lInBase64) { lBuffer.Flush(); lBytes.Add(cASCII.HYPEN); lInBase64 = false; } return(lBytes); }
}); // the byte 0-255 to be decoded is the index and the value at that position in the array is the byte that is encoded or -1 if this byte encodes nothing public static cByteList Encode(IList <byte> pBytes) { if (pBytes.Count == 0) { return(new cByteList()); } var lBytes = new cByteList((pBytes.Count + 2) / 3 * 4); var lBuffer = new cToBase64Buffer(lBytes); foreach (byte lByte in pBytes) { lBuffer.Add(lByte); } lBuffer.Flush(); return(lBytes); }