예제 #1
0
        public string decrypt(string text, string password)
        {
            core   c = new core();
            random r = new random();

            byte[] baPwd = Encoding.UTF8.GetBytes(password);

            // Hash the password with SHA256
            byte[] baPwdHash = SHA256Managed.Create().ComputeHash(baPwd);

            byte[] baText = Convert.FromBase64String(text);

            byte[] baDecrypted = c.decrypt(baText, baPwdHash);

            // Remove salt
            int saltLength = r.GetSaltLength();

            byte[] baResult = new byte[baDecrypted.Length - saltLength];
            for (int i = 0; i < baResult.Length; i++)
            {
                baResult[i] = baDecrypted[i + saltLength];
            }

            string result = Encoding.UTF8.GetString(baResult);

            return(result);
        }
예제 #2
0
        public void DecryptFile(string inputEncryptedFile, string outputDecryptedFile, string password)
        {
            core c = new core();

            byte[] bytesToBeDecrypted = File.ReadAllBytes(inputEncryptedFile);
            byte[] passwordBytes      = Encoding.UTF8.GetBytes(password);
            passwordBytes = SHA256.Create().ComputeHash(passwordBytes);

            byte[] bytesDecrypted = c.decrypt(bytesToBeDecrypted, passwordBytes);

            File.WriteAllBytes(outputDecryptedFile, bytesDecrypted);
        }
예제 #3
0
        public string decrypt(string input, string password)
        {
            core c = new core();

            // Get the bytes of the string
            byte[] bytesToBeDecrypted = Convert.FromBase64String(input);
            byte[] passwordBytes      = Encoding.UTF8.GetBytes(password);
            passwordBytes = SHA256.Create().ComputeHash(passwordBytes);

            byte[] bytesDecrypted = c.decrypt(bytesToBeDecrypted, passwordBytes);

            string result = Encoding.UTF8.GetString(bytesDecrypted);

            return(result);
        }