/// <summary> /// Compute rest of encryption of the partially encrypted data /// </summary> /// <param name="encryptionService">Encryption service to use for encryption</param> /// <param name="keyPassword">Hash of main password</param> public void ComputeRestOfEncryption(EncryptionService encryptionService, byte[] keyPassword) { Encrypted = encryptionService.Encrypt(keyPassword, EncryptedPart); var check = encryptionService.Decrypt(keyPassword, Encrypted); if (check != EncryptedPart) { throw new Exception("Can not be decrypted, step 2."); } }
/// <summary> /// Compute partial encryption of the original data based on individual key derived from hash of main password and <see cref="Salt"/> /// </summary> /// <param name="encryptionService">Encryption service to use for encryption</param> /// <param name="keyPassword">Hash of main password</param> public void ComputePartEncryption(EncryptionService encryptionService, byte[] keyPassword) { if (Original != null) { if (Salt == null) { Salt = encryptionService.GenerateRandomCryptographicKey(32); } var newKeyPassword = encryptionService.GetIndividualKeyInBytes(keyPassword, Salt); EncryptedPart = encryptionService.Encrypt(newKeyPassword, Original.ToString()); var check = encryptionService.Decrypt(newKeyPassword, EncryptedPart); if (check != Original.ToString()) { throw new Exception("Can not be decrypted."); } Original = null; } }