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.
Inheritance
Namespace: Libplanet.Crypto
Assembly: Libplanet.Crypto.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 |
---|---|---|
System.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<System.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 |
---|---|---|
System.Byte[] | ciphertext | The encrypted data. |
System.Int32 | nonSecretLength | The length of |
Returns
Type | Description |
---|---|
System.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 |
---|---|---|
System.Byte[] | message | A binary data to be encrypted. |
System.Byte[] | nonSecret | An extra data not to be encrypted, but to be just transmitted as is. The default value is null, which means empty. |
Returns
Type | Description |
---|---|
System.Byte[] | A ciphertext that was encrypted from the |
See Also
| Improve this Doc View SourceEquals(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.
Declaration
public bool Equals(SymmetricKey other)
Parameters
Type | Name | Description |
---|---|---|
SymmetricKey | other |
Returns
Type | Description |
---|---|
System.Boolean |
Equals(Nullable<Object>)
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.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Object> | obj |
Returns
Type | Description |
---|---|
System.Boolean |
GetHashCode()
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.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
ToByteArray()
Gets a mutable
Declaration
public byte[] ToByteArray()
Returns
Type | Description |
---|---|
System.Byte[] | A new mutable |
See Also
Operators
| Improve this Doc View SourceEquality(SymmetricKey, 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.
Declaration
public static bool operator ==(SymmetricKey left, SymmetricKey right)
Parameters
Type | Name | Description |
---|---|---|
SymmetricKey | left | |
SymmetricKey | right |
Returns
Type | Description |
---|---|
System.Boolean |
Inequality(SymmetricKey, 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.
Declaration
public static bool operator !=(SymmetricKey left, SymmetricKey right)
Parameters
Type | Name | Description |
---|---|---|
SymmetricKey | left | |
SymmetricKey | right |
Returns
Type | Description |
---|---|
System.Boolean |