Exemple #1
0
        /// <summary>
        /// Gets the platform enum value for the padding used by the specified algorithm.
        /// </summary>
        /// <param name="algorithm">The algorithm.</param>
        /// <returns>The platform-specific enum value for the padding.</returns>
        private static Platform.PaddingMode GetPadding(SymmetricAlgorithm algorithm)
        {
            switch (algorithm.GetPadding())
            {
            case SymmetricAlgorithmPadding.None:
                return(Platform.PaddingMode.None);

            case SymmetricAlgorithmPadding.PKCS7:
                return(Platform.PaddingMode.PKCS7);

            default:
                throw new ArgumentException();
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets the padding substring to include in the string
        /// passed to <see cref="Cipher.GetInstance(string)"/>
        /// </summary>
        /// <param name="algorithm">The algorithm.</param>
        /// <returns>A value such as "PKCS7Padding", or <c>null</c> if no padding.</returns>
        private static string GetPadding(SymmetricAlgorithm algorithm)
        {
            switch (algorithm.GetPadding())
            {
            case SymmetricAlgorithmPadding.None:
                return(null);

            case SymmetricAlgorithmPadding.PKCS7:
                return("PKCS7Padding");

            default:
                throw new NotSupportedException();
            }
        }
 /// <summary>
 /// Gets the padding substring to include in the string
 /// passed to <see cref="Cipher.GetInstance(string)"/>
 /// </summary>
 /// <param name="algorithm">The algorithm.</param>
 /// <returns>A value such as "PKCS7Padding", or <c>null</c> if no padding.</returns>
 private static string GetPadding(SymmetricAlgorithm algorithm)
 {
     switch (algorithm.GetPadding())
     {
         case SymmetricAlgorithmPadding.None:
             return null;
         case SymmetricAlgorithmPadding.PKCS7:
             return "PKCS7Padding";
         default:
             throw new NotSupportedException();
     }
 }
        /// <summary>Returns a crypto key management for a specified algorithm.</summary>
        /// <param name="factory">The factory.</param>
        /// <param name="algorithm">The algorithm.</param>
        /// <returns>An instance of <see cref="ISymmetricKeyAlgorithmProvider"/>.</returns>
        public static ISymmetricKeyAlgorithmProvider OpenAlgorithm(this ISymmetricKeyAlgorithmProviderFactory factory, SymmetricAlgorithm algorithm)
        {
            Requires.NotNull(factory, nameof(factory));

            return(factory.OpenAlgorithm(algorithm.GetName(), algorithm.GetMode(), algorithm.GetPadding()));
        }
        /// <summary>
        /// Returns a crypto key management for a specified algorithm.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="algorithm">The algorithm.</param>
        /// <returns>An instance of <see cref="ISymmetricKeyAlgorithmProvider"/>.</returns>
        public static ISymmetricKeyAlgorithmProvider OpenAlgorithm(this ISymmetricKeyAlgorithmProviderFactory factory, SymmetricAlgorithm algorithm)
        {
            Requires.NotNull(factory, nameof(factory));

            return factory.OpenAlgorithm(algorithm.GetName(), algorithm.GetMode(), algorithm.GetPadding());
        }