Class CryptoRSA
Authenticator based on 2048-bit RSA (Rivest–Shamir–Adleman).
Inheritance
Namespace: SuperNet.Netcode.Crypto
Assembly: cs.temp.dll.dll
Syntax
public sealed class CryptoRSA : ICryptoAuthenticator, IDisposable
Constructors
CryptoRSA(Allocator)
Create a new RSA authenticator.
Declaration
public CryptoRSA(Allocator allocator = null)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | Allocator to use for keys or null for none. |
Properties
SignatureLength
Number of bytes in the signature. For RSA this is 256.
Declaration
public int SignatureLength { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
Dispose()
Instantly dispose of all resources.
Declaration
public void Dispose()
ExportPrivateKey()
Export all RSA parameters as a Base64 string.
Declaration
public string ExportPrivateKey()
Returns
Type | Description |
---|---|
System.String | Base64 encoded parameters. |
ExportPublicKey()
Export RSA modulus as a Base64 string.
Declaration
public string ExportPublicKey()
Returns
Type | Description |
---|---|
System.String | Base64 encoded RSA modulus. |
ImportPrivateKey(String)
Import previously exported private key.
Declaration
public void ImportPrivateKey(string privateKey)
Parameters
Type | Name | Description |
---|---|---|
System.String | privateKey | Private key to import. |
Sign(ArraySegment<Byte>, ArraySegment<Byte>)
Generate a signature of that can then be verified by the public key.
Declaration
public void Sign(ArraySegment<byte> data, ArraySegment<byte> output)
Parameters
Type | Name | Description |
---|---|---|
ArraySegment<System.Byte> | data | Data to sign. |
ArraySegment<System.Byte> | output | Output to write signature to. |
Verify(ArraySegment<Byte>, ArraySegment<Byte>, String)
Verify that signature has been signed by someone with the private key.
Declaration
public bool Verify(ArraySegment<byte> data, ArraySegment<byte> signature, string remotePublicKey)
Parameters
Type | Name | Description |
---|---|---|
ArraySegment<System.Byte> | data | Data that has been signed. |
ArraySegment<System.Byte> | signature | Signature that has been generated. |
System.String | remotePublicKey | Public key corresponding to the private key that signed the data. |
Returns
Type | Description |
---|---|
System.Boolean | True if verified, false if not. |