/// <summary> /// Adds padding data to a buffer buf whose original size /// is unpadded_buflen in order to extend its total length /// to a multiple of blocksize. /// </summary> /// <returns>The pad.</returns> /// <param name="text">Text.</param> public static byte[] Pad(string text) { Guard.Argument(text, nameof(text)).NotNull().NotEmpty(); var buf = Encoding.UTF8.GetBytes(text); var bufOrigialSize = buf.Length; ulong paddedBufLenp = 0; Array.Resize(ref buf, 540); SodiumPadding.Pad(ref paddedBufLenp, buf, (ulong)buf.Length, 32, int.MaxValue); Array.Resize(ref buf, (int)paddedBufLenp); paddedBufLenp = 0; for (int i = bufOrigialSize; i < buf.Length; i++) { { SodiumPadding.Pad(ref paddedBufLenp, buf, (ulong)i, 32, int.MaxValue); } } return(buf); }
/// <summary> /// Adds padding data to a buffer buf whose original size /// is unpadded_buflen in order to extend its total length /// to a multiple of blocksize. /// </summary> /// <returns>The pad.</returns> /// <param name="text">Text.</param> public static byte[] Pad(string text) { if (string.IsNullOrEmpty(text)) { throw new ArgumentException("message", nameof(text)); } var buf = Encoding.UTF8.GetBytes(text); var bufOrigialSize = buf.Length; ulong paddedBufLenp = 0; Array.Resize(ref buf, 540); SodiumPadding.Pad(ref paddedBufLenp, buf, (ulong)buf.Length, 32, int.MaxValue); Array.Resize(ref buf, (int)paddedBufLenp); paddedBufLenp = 0; for (int i = bufOrigialSize; i < buf.Length; i++) { { SodiumPadding.Pad(ref paddedBufLenp, buf, (ulong)i, 32, int.MaxValue); } } return(buf); }