-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSisCryptoHighLevel.cs
More file actions
28 lines (26 loc) · 987 Bytes
/
SisCryptoHighLevel.cs
File metadata and controls
28 lines (26 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
namespace SisCrypto {
public static partial class SisCrypto {
public const int SISCRYPTO_LATEST_VERSION = 1;
public static PasswordEncryptResult PasswordEncrypt(
Secret<string> password, string data,
int version = SISCRYPTO_LATEST_VERSION
) {
var keyResult = DeriveKey(password, version);
var encryptResult = SymmetricEncrypt(keyResult.Key, data, version);
return new PasswordEncryptResult(
encryptResult.Encrypted,
keyResult.Salt,
encryptResult.Salt,
version
);
}
public static string PasswordDecrypt(Secret<string> password, PasswordEncryptResult data) {
var keyResult = DeriveKey(password, data.KeySalt, data.Version);
var decryptResult = SymmetricDecrypt(
keyResult.Key,
new SymmetricEncryptResult(data.Data, data.EncryptSalt, data.Version)
);
return BytesToString(decryptResult, data.Version)!;
}
}
}