Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EncryptionService"/> class.
 /// </summary>
 /// <param name="encryptionDTO">The encryption dto.</param>
 /// <exception cref="ArgumentNullException">
 /// encryptionDTO
 /// or
 /// UserName
 /// or
 /// Password
 /// or
 /// InputFileName
 /// or
 /// OutputFileName
 /// </exception>
 public EncryptionService(EncryptionDTO encryptionDTO)
 {
     _encryptionDTO = encryptionDTO ?? throw new ArgumentNullException(nameof(encryptionDTO));
     if (string.IsNullOrEmpty(encryptionDTO.UserName))
     {
         throw new ArgumentNullException(nameof(encryptionDTO.UserName));
     }
     if (string.IsNullOrEmpty(encryptionDTO.Password))
     {
         throw new ArgumentNullException(nameof(encryptionDTO.Password));
     }
     if (string.IsNullOrEmpty(encryptionDTO.InputFileName))
     {
         throw new ArgumentNullException(nameof(encryptionDTO.InputFileName));
     }
     if (string.IsNullOrEmpty(encryptionDTO.OutputFileName))
     {
         throw new ArgumentNullException(nameof(encryptionDTO.OutputFileName));
     }
 }
Ejemplo n.º 2
0
        public EncryptionDTO StandardMD5Decryption(string cipher)
        {
            using (var md5 = new MD5CryptoServiceProvider())
            {
                using (var tdes = new TripleDESCryptoServiceProvider())
                {
                    EncryptionDTO result = new EncryptionDTO();
                    result.Key        = MD5Property.StandardMD5Key;
                    result.CipherText = cipher;

                    tdes.Key     = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(result.Key));
                    tdes.Mode    = CipherMode.ECB;
                    tdes.Padding = PaddingMode.PKCS7;

                    using (var transform = tdes.CreateDecryptor())
                    {
                        byte[] cipherBytes = Convert.FromBase64String(result.CipherText);
                        byte[] bytes       = transform.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length);
                        result.PlainText = UTF8Encoding.UTF8.GetString(bytes);
                        return(result);
                    }
                }
            }
        }