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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
namespace Devolutions.Cryptography.Signature
{
using System;
/// <summary>
/// Class used to represent a signing key pair from Devolutions Crypto.
/// </summary>
public class SigningKeyPair
{
/// <summary>
/// Initializes a new instance of the <see cref="SigningKeyPair"/> class.
/// </summary>
public SigningKeyPair()
{
}
/// <summary>
/// Gets or sets the raw key pair data.
/// </summary>
internal byte[] Payload { get; set; }
/// <summary>
/// Deserialize the SigningKeyPair class from a little endian byte array.
/// </summary>
/// <param name="data">The data to deserialize.</param>
/// <returns>Returns the deserialized parameters.</returns>
public static SigningKeyPair FromByteArray(byte[] data)
{
SigningKeyPair keypair = new SigningKeyPair();
keypair.Payload = data;
return keypair;
}
/// <summary>
/// Extract the public key from the key pair.
/// </summary>
/// <returns>Returns the extracted public key.</returns>
public SigningPublicKey GetPublicKey()
{
byte[] publicKeyNative = new byte[Native.GetSigningPublicKeySize(this.Payload, (UIntPtr)this.Payload.Length)];
long res = Native.GetSigningPublicKey(this.Payload, (UIntPtr)this.Payload.Length, publicKeyNative, (UIntPtr)publicKeyNative.Length);
if (res < 0)
{
Utils.HandleError(res);
}
return SigningPublicKey.FromByteArray(publicKeyNative);
}
/// <summary>
/// Serialize the SigningKeyPair class to a little endian byte array.
/// </summary>
/// <returns>Returns SigningKeyPair class to a little endian byte array.</returns>
public byte[] ToByteArray()
{
return this.Payload;
}
}
}