public static SimpleEncrypt ( byte secretMessage, byte cryptKey, byte authKey, byte nonSecretPayload = null ) : byte[] | ||
secretMessage | byte | |
cryptKey | byte | |
authKey | byte | |
nonSecretPayload | byte | |
Résultat | byte[] |
public static byte[] SimpleEncryptWithPassword(byte[] secretMessage, string password, byte[] nonSecretPayload = null) { nonSecretPayload = nonSecretPayload ?? new byte[0]; if (secretMessage == null || secretMessage.Length == 0) { throw new ArgumentException("Secret Message Required!", nameof(secretMessage)); } byte[] nonSecretPayload1 = new byte[AESThenHMAC.SaltBitSize / 8 * 2 + nonSecretPayload.Length]; Array.Copy((Array)nonSecretPayload, (Array)nonSecretPayload1, nonSecretPayload.Length); int length = nonSecretPayload.Length; byte[] bytes1; using (Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, AESThenHMAC.SaltBitSize / 8, AESThenHMAC.Iterations)) { byte[] salt = rfc2898DeriveBytes.Salt; bytes1 = rfc2898DeriveBytes.GetBytes(AESThenHMAC.KeyBitSize / 8); Array.Copy((Array)salt, 0, (Array)nonSecretPayload1, length, salt.Length); length += salt.Length; } byte[] bytes2; using (Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, AESThenHMAC.SaltBitSize / 8, AESThenHMAC.Iterations)) { byte[] salt = rfc2898DeriveBytes.Salt; bytes2 = rfc2898DeriveBytes.GetBytes(AESThenHMAC.KeyBitSize / 8); Array.Copy((Array)salt, 0, (Array)nonSecretPayload1, length, salt.Length); } return(AESThenHMAC.SimpleEncrypt(secretMessage, bytes1, bytes2, nonSecretPayload1)); }
public static string SimpleEncrypt(string secretMessage, byte[] cryptKey, byte[] authKey, byte[] nonSecretPayload = null) { if (string.IsNullOrEmpty(secretMessage)) { throw new ArgumentException("Secret Message Required!", nameof(secretMessage)); } return(Convert.ToBase64String(AESThenHMAC.SimpleEncrypt(Encoding.UTF8.GetBytes(secretMessage), cryptKey, authKey, nonSecretPayload))); }