Class SymmetricKey
An AES-GCM symmetric key. Unlike PrivateKey and PublicKey that are involved in an asymmetric key cryptography, it uses the same SymmetricKey for both encrypting a plaintext and decrypting a ciphertext.
Namespace: Libplanet.Crypto
Assembly: Libplanet.dll
Syntax
public class SymmetricKey : IEquatable<SymmetricKey>
Constructors
| Improve this Doc View SourceSymmetricKey(Byte[])
Creates a SymmetricKey instance from the given
key
),
which encodes a valid AES-GCM symmetric key.
Declaration
public SymmetricKey(byte[] key)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | key | A valid |
Remarks
A valid
See Also
Properties
| Improve this Doc View SourceByteArray
An immutable
Declaration
public ImmutableArray<byte> ByteArray { get; }
Property Value
Type | Description |
---|---|
ImmutableArray<Byte> |
Remarks
This is immutable. For a mutable array, call ToByteArray() method.
See Also
Methods
| Improve this Doc View SourceDecrypt(Byte[], Int32)
Converts a ciphertext
which was encrypted with
the same key to the plain message.
Declaration
public byte[] Decrypt(byte[] ciphertext, int nonSecretLength = 0)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | ciphertext | The encrypted data. |
Int32 | nonSecretLength | The length of |
Returns
Type | Description |
---|---|
Byte[] | The plain data the |
Remarks
Although the parameter name ciphertext
has the
word “text”, both a ciphertext
and a returned message are a
See Also
| Improve this Doc View SourceEncrypt(Byte[], Byte[])
Converts a plain message
to a ciphertext
which can be decrypted with the same key.
Declaration
public byte[] Encrypt(byte[] message, byte[] nonSecret = null)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | message | A binary data to be encrypted. |
Byte[] | nonSecret | An extra data not to be encrypted, but
to be just transmitted as is. The default value is |
Returns
Type | Description |
---|---|
Byte[] | A ciphertext that was encrypted from the |
See Also
| Improve this Doc View SourceEquals(SymmetricKey)
Declaration
public bool Equals(SymmetricKey other)
Parameters
Type | Name | Description |
---|---|---|
SymmetricKey | other |
Returns
Type | Description |
---|---|
Boolean |
Equals(Nullable<Object>)
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
Nullable<Object> | obj |
Returns
Type | Description |
---|---|
Boolean |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 |
ToByteArray()
Gets a mutable
Declaration
public byte[] ToByteArray()
Returns
Type | Description |
---|---|
Byte[] | A new mutable |
See Also
Operators
| Improve this Doc View SourceEquality(SymmetricKey, SymmetricKey)
Declaration
public static bool operator ==(SymmetricKey left, SymmetricKey right)
Parameters
Type | Name | Description |
---|---|---|
SymmetricKey | left | |
SymmetricKey | right |
Returns
Type | Description |
---|---|
Boolean |
Inequality(SymmetricKey, SymmetricKey)
Declaration
public static bool operator !=(SymmetricKey left, SymmetricKey right)
Parameters
Type | Name | Description |
---|---|---|
SymmetricKey | left | |
SymmetricKey | right |
Returns
Type | Description |
---|---|
Boolean |