Exemple #1
0
        /// <summary>
        /// Decrypts the <paramref name="encrypted"/> text to a <see cref="short"/> value.
        /// </summary>
        /// <param name="cipher">The cipher.</param>
        /// <param name="encrypted">The encrypted text.</param>
        /// <returns>The decrypted value.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="cipher"/> or <paramref name="encrypted"/> are <see langword="null"/>.</exception>
        public static short DecryptInt16(
            this ICipher cipher,
            byte[] encrypted)
        {
            if (cipher == null)
            {
                throw new ArgumentNullException(nameof(cipher));
            }
            if (encrypted == null)
            {
                throw new ArgumentNullException(nameof(encrypted));
            }

            var decrypted = cipher.Decrypt(encrypted);

            if (decrypted.Length < 2)
            {
                throw new ArgumentException(Resources.InvalidEncryptedValue);
            }

            return(FromByteArray.ToInt16(decrypted));
        }