using System; using System.Collections.Generic; using System.Threading.Tasks; using Bit.Core.Enums; using Bit.Core.Models.Domain; using Bit.Core.Models.Response; namespace Bit.Core.Abstractions { public interface ICryptoService { void ClearCache(); Task RefreshKeysAsync(); Task SetUserKeyAsync(UserKey userKey, string userId = null); Task GetUserKeyAsync(string userId = null); Task IsLegacyUserAsync(MasterKey masterKey = null, string userId = null); Task GetUserKeyWithLegacySupportAsync(string userId = null); Task HasUserKeyAsync(string userId = null); Task HasEncryptedUserKeyAsync(string userId = null); Task MakeUserKeyAsync(); Task ClearUserKeyAsync(string userId = null); Task SetMasterKeyEncryptedUserKeyAsync(string value, string userId = null); Task GetAutoUnlockKeyAsync(string userId = null); Task HasAutoUnlockKeyAsync(string userId = null); Task GetBiometricUnlockKeyAsync(string userId = null); Task SetMasterKeyAsync(MasterKey masterKey, string userId = null); Task GetMasterKeyAsync(string userId = null); Task MakeMasterKeyAsync(string password, string email, KdfConfig kdfConfig); Task ClearMasterKeyAsync(string userId = null); Task> EncryptUserKeyWithMasterKeyAsync(MasterKey masterKey, UserKey userKey = null); Task DecryptUserKeyWithMasterKeyAsync(MasterKey masterKey, EncString encUserKey = null, string userId = null); Task> MakeDataEncKeyAsync(SymmetricCryptoKey key); Task HashMasterKeyAsync(string password, MasterKey key, HashPurpose hashPurpose = HashPurpose.ServerAuthorization); Task SetMasterKeyHashAsync(string keyHash); Task GetMasterKeyHashAsync(); Task ClearMasterKeyHashAsync(string userId = null); Task CompareAndUpdateKeyHashAsync(string masterPassword, MasterKey key); Task SetOrgKeysAsync(IEnumerable orgs); Task GetOrgKeyAsync(string orgId); Task> GetOrgKeysAsync(); Task ClearOrgKeysAsync(bool memoryOnly = false, string userId = null); Task GetUserPublicKeyAsync(); Task SetUserPrivateKeyAsync(string encPrivateKey); Task GetUserPrivateKeyAsync(); Task> GetFingerprintAsync(string userId, byte[] publicKey = null); Task> MakeKeyPairAsync(SymmetricCryptoKey key = null); Task ClearKeyPairAsync(bool memoryOnly = false, string userId = null); Task MakePinKeyAsync(string pin, string salt, KdfConfig config); Task ClearPinKeysAsync(string userId = null); Task DecryptUserKeyWithPinAsync(string pin, string salt, KdfConfig kdfConfig, EncString pinProtectedUserKey = null); Task DecryptMasterKeyWithPinAsync(string pin, string salt, KdfConfig kdfConfig, EncString pinProtectedMasterKey = null); Task MakeSendKeyAsync(byte[] keyMaterial); Task RsaEncryptAsync(byte[] data, byte[] publicKey = null); Task RsaDecryptAsync(string encValue, byte[] privateKey = null); Task RandomNumberAsync(int min, int max); Task RandomStringAsync(int length); Task DecryptFromBytesAsync(byte[] encBytes, SymmetricCryptoKey key); Task DecryptToBytesAsync(EncString encString, SymmetricCryptoKey key = null); Task DecryptToUtf8Async(EncString encString, SymmetricCryptoKey key = null); Task EncryptAsync(byte[] plainValue, SymmetricCryptoKey key = null); Task EncryptAsync(string plainValue, SymmetricCryptoKey key = null); Task EncryptToBytesAsync(byte[] plainValue, SymmetricCryptoKey key = null); Task DecryptAndMigrateOldPinKeyAsync(bool masterPasswordOnRestart, string pin, string email, KdfConfig kdfConfig, EncString oldPinKey); Task GetOrDeriveMasterKeyAsync(string password, string userId = null); Task UpdateMasterKeyAndUserKeyAsync(MasterKey masterKey); Task HashAsync(string value, CryptoHashAlgorithm hashAlgorithm); Task ValidateUriChecksumAsync(EncString remoteUriChecksum, string rawUri, string orgId, SymmetricCryptoKey key); } }