private static byte[] ParseByteArray(string name, string normalizedType, string normalizedValue)
        {
            var bytesCount = normalizedType.Length > 5
                ? int.Parse(normalizedType.Substring(5))
                : (int?)null;

            if (normalizedValue != string.Empty && !M_HexRegex.IsMatch(normalizedValue))
            {
                throw new ArgumentParsingException(name, normalizedValue, "not a byte array value");
            }
            var bytes = HexHelper.FromHex(normalizedValue);

            if (bytesCount != null && bytes.Length != bytesCount)
            {
                throw new ArgumentParsingException(name, normalizedValue,
                                                   $"{bytesCount}-byte array value must have exactly {bytesCount} bytes");
            }
            return(bytes);
        }
Пример #2
0
        public void EncryptDecrypBytesTest()
        {
            var inputString = SH.Join("", RandomHelper.vsZnaky);
            var input       = Encoding.UTF8.GetBytes(inputString).ToList();

            var encrypted = CryptHelper.RijndaelBytes.Instance.Encrypt(input);

            var hexEncrypted   = HexHelper.ToHex(encrypted);
            var encryptedBytes = HexHelper.FromHex(hexEncrypted);

            var decrypted = CryptHelper.RijndaelBytes.Instance.Decrypt(encryptedBytes);

            CA.RemovePadding <byte>(decrypted, 0);

            var s = Encoding.UTF8.GetString(decrypted.ToArray());



            Assert.Equal(inputString, s);
        }