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.
Inherited Members
Namespace: Libplanet.Crypto
Assembly: Libplanet.dll
Syntax
[GeneratedEquality]
public class SymmetricKey
Constructors
| Improve this Doc View SourceSymmetricKey(Byte[])
Creates a SymmetricKey instance from the given
Byte array (i.e., key
),
which encodes a valid AES-GCM symmetric key.
Declaration
public SymmetricKey(byte[] key)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | key | A valid Byte array that encodes an AES-GCM symmetric key. |
Remarks
A valid Byte array for a SymmetricKey can be encoded using ToByteArray() method.
See Also
Properties
| Improve this Doc View SourceByteArray
An immutable Byte array encoding of this key.
Declaration
[EqualityKey(KeyEqualityMode.Auto)]
[Pure]
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
[Pure]
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 Byte string,
not a Unicode String.
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
[Pure]
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 SourceToByteArray()
Gets a mutable Byte array which encodes this key.
Declaration
[Pure]
public byte[] ToByteArray()
Returns
Type | Description |
---|---|
Byte[] | A new mutable Byte array which encodes this key. Since it is created every time the method is called, any mutation on that does not affect this SymmetricKey object. |