private byte[] SerializeAndEncrypt(IEnumerable <int> safeByteIdList, byte[] encryptionKey) { var serialization = Serialize(safeByteIdList); var encrypted = _encryptor.Encrypt(serialization, encryptionKey); return(encrypted); }
public void Protect(byte[] userData) { if (userData == null) { throw new ArgumentNullException(nameof(userData)); } var encryptedBytes = _encryptor.Encrypt(userData, _key); SetBytesToByteArray( source: encryptedBytes, target: ref userData); }
private void Encrypt(byte b) { //Mix the with arbitrary bytes _realBytePosition = _fastRandom.GetInt(0, SaltSize); var arbitraryBytes = _fastRandom.GetBytes(SaltSize); RuntimeHelper.ExecuteCodeWithGuaranteedCleanup( //Action () => { arbitraryBytes[_realBytePosition] = b; //Get key _encryptionKey = _fastRandom.GetBytes(KeySize); //Encrypt var encryptedBuffer = _encryptor.Encrypt(arbitraryBytes, _encryptionKey); RuntimeHelper.ExecuteCodeWithGuaranteedCleanup( //Action () => { //Add arbitrary bytes _encryptedByteLength = encryptedBuffer.Length; _encryptedByte = GetMemoryProtectableSizedBytes(encryptedBuffer); }, //Cleanup () => { if (encryptedBuffer != null) { Array.Clear(encryptedBuffer, 0, encryptedBuffer.Length); } }); }, //Cleanup () => { Array.Clear(arbitraryBytes, 0, arbitraryBytes.Length); }); }