-
Notifications
You must be signed in to change notification settings - Fork 139
/
ICryptoBackend.cs
46 lines (44 loc) · 2.04 KB
/
ICryptoBackend.cs
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Security.Cryptography;
namespace Libplanet.Crypto
{
/// <summary>
/// Cryptography backend interface.
/// </summary>
/// <typeparam name="T">A <see cref="HashAlgorithm"/> which corresponds to a digest.</typeparam>
/// <seealso cref="HashAlgorithm"/>
public interface ICryptoBackend<T>
where T : HashAlgorithm
{
/// <summary>
/// Creates a signature from <paramref name="messageHash"/> with the corresponding
/// <paramref name="privateKey"/>.
/// </summary>
/// <param name="messageHash">A 32 bytes message hash digest hashed with SHA256 to sign.
/// </param>
/// <param name="privateKey"><see cref="PrivateKey"/> to sign
/// <paramref name="messageHash"/>.
/// </param>
/// <returns> Created a signature from <paramref name="messageHash"/> with the corresponding
/// <paramref name="privateKey"/>.
/// </returns>
byte[] Sign(HashDigest<T> messageHash, PrivateKey privateKey);
/// <summary>
/// Verifies whether a <paramref name="signature"/> was created from
/// a <paramref name="messageHash"/> with the corresponding <see cref="PrivateKey"/>.
/// </summary>
/// <param name="messageHash">A 32 bytes message hash digest hashed with SHA256.</param>
/// <param name="signature">A signature that was created from the
/// <paramref name="messageHash"/>.</param>
/// <param name="publicKey"><see cref="PublicKey"/> used for verification.</param>
/// <returns><c>true</c> if the <paramref name="signature"/> was created
/// from the <paramref name="messageHash"/> with the corresponding
/// <see cref="PrivateKey"/>. Otherwise <c>false</c>.</returns>
/// <exception cref="Exception">If any exception is thrown, the given
/// <paramref name="signature"/> is considered as invalid.</exception>
bool Verify(
HashDigest<T> messageHash,
byte[] signature,
PublicKey publicKey);
}
}