public EncryptionDecryption(IEncryptionKey encryptionKey, IDigitalSigning digitalSigning) { key = encryptionKey.GetEncryptionKey(); encoding = Encoding.ASCII; padding = new Pkcs7Padding(); this.digitalSigning = digitalSigning; }
public byte[] Decrypt(byte[] input, IEncryptionKey key = null) { if (key == null) { key = Key; } return(_decryptor.Decrypt(input, key)); }
public Span <byte> Decrypt(Span <byte> encryptedBytes, IEncryptionKey keyParameter) { var key = keyParameter as StringKey ?? throw new ArgumentException($"{nameof(keyParameter)} is not {nameof(StringKey)}."); var passwordBytes = Encoding.UTF8.GetBytes(key.Password); throw new NotImplementedException(); //return (sourceBytes, SHA256.HashData(passwordBytes), passwordBytes); }
public bool Validate(IEncryptionKey key, EncryptionAlgorithm algorithm) { if (algorithm == EncryptionAlgorithm.Rijndael) { if (key.IV.Length != 16) { return(false); } if (key.Key.Length * 8 < 128 || key.Key.Length * 8 > 263) { return(false); } } else if (algorithm == EncryptionAlgorithm.Des) { if (key.IV.Length != 8) { return(false); } if (key.Key.Length * 8 < 64 || key.Key.Length * 8 > 71) { return(false); } } else if (algorithm == EncryptionAlgorithm.Rc2) { if (key.IV.Length != 8) { return(false); } if (key.Key.Length * 8 < 40 || key.Key.Length * 8 > 135) { return(false); } } else if (algorithm == EncryptionAlgorithm.TripleDes) { if (key.IV.Length != 8) { return(false); } if (key.Key.Length * 8 < 128 || key.Key.Length * 8 > 199) { return(false); } } var input = new byte[1024]; rnd.NextBytes(input); var encryptor = _factory.EncryptionForAlgorithm(algorithm); var output = encryptor.Decrypt(encryptor.Encrypt(input, key), key); var same = input.SequenceEqual(output); return(same); }
public static RijndaelManaged CreateRijndael(IEncryptionKey encryptionKey) { return(new RijndaelManaged() { Mode = CipherMode.CBC, BlockSize = 128, KeySize = KeySize, Padding = PaddingMode.PKCS7, Key = encryptionKey.GetKeyBytes(KeySize), IV = encryptionKey.GetIvBytes(), }); }
public byte[] Encrypt(byte[] bytesData, IEncryptionKey key = null) { using (var memoryStream = new MemoryStream()) { if (key?.IV != null) { transformer.IV = key.IV; } else { transformer.IV = IV; } using (var iCryptoTransform = transformer.GetCryptoServiceProvider(key.Key)) { using (var cryptoStream = new CryptoStream(memoryStream, iCryptoTransform, CryptoStreamMode.Write)) { try { cryptoStream.Write(bytesData, 0, bytesData.Length); } catch (Exception e) { throw new Exception( string.Concat("Error while writing encrypted data to the stream: \n", e.Message)); } Key = transformer.Key; if (key.IV != null) { IV = transformer.IV; } else { IV = transformer.IV; } cryptoStream.FlushFinalBlock(); cryptoStream.Close(); } return(memoryStream.ToArray()); } } }
public AssetBundleEncryptor(string planeAssetBundleDirPath, string encryptedAssetBundleDirPath, IEncryptionKey encryptionKey) { this.PlaneAssetBundleDirPath = planeAssetBundleDirPath; this.EncryptedAssetBundleDirPath = encryptedAssetBundleDirPath; RijndaelManaged rijndael = Decryptor.CreateRijndael(encryptionKey); encryptor = rijndael.CreateEncryptor(); }
public void WriteKeyForIntent(EncryptionIntent intent, IEncryptionKey key) { throw new NotImplementedException(); }
public Decryptor(IEncryptionKey encryptionKey) { RijndaelManaged rijndael = CreateRijndael(encryptionKey); decryptor = rijndael.CreateDecryptor(); }