• Design
  • API Reference
  • Changelog
  • Contribute
Show / Hide Table of Contents
  • Libplanet
    • Address
    • AddressExtension
    • ByteUtil
    • Hashcash
    • Hashcash.Stamp
    • HashDigest<T>
    • HashDigestExtension
    • Nonce
  • Libplanet.Action
    • AccountStateGetter
    • ActionEvaluation<T>
    • ActionTypeAttribute
    • AddressStateMap
    • IAccountStateDelta
    • IAction
    • IActionContext
    • IRandom
    • MissingActionTypeException
    • PolymorphicAction<T>
  • Libplanet.Blockchain
    • BlockChain<T>
  • Libplanet.Blockchain.Policies
    • BlockPolicy<T>
    • BlockPolicyExtension
    • IBlockPolicy<T>
  • Libplanet.Blocks
    • Block<T>
    • InvalidBlockDifficultyException
    • InvalidBlockException
    • InvalidBlockHashException
    • InvalidBlockIndexException
    • InvalidBlockNonceException
    • InvalidBlockPreviousHashException
    • InvalidBlockTimestampException
  • Libplanet.Crypto
    • InvalidCiphertextException
    • PrivateKey
    • PublicKey
    • SymmetricKey
  • Libplanet.Net
    • BlockDownloadState
    • DifferentAppProtocolVersionException
    • DifferentProtocolVersionEventArgs
    • IceServer
    • IceServerException
    • InvalidMessageException
    • NoSwarmContextException
    • Peer
    • PeerNotFoundException
    • PeerSetDelta
    • Swarm
    • SwarmException
  • Libplanet.Serialization
    • BencodexFormatter<T>
    • SerializationInfoExtension
  • Libplanet.Store
    • BaseIndex<TKey, TVal>
    • BaseStore
    • BlockSet<T>
    • FileStore
    • IStore
    • NamespaceNotFoundException
    • TransactionSet<T>
  • Libplanet.Tx
    • InvalidTxException
    • InvalidTxIdException
    • InvalidTxNonceException
    • InvalidTxPublicKeyException
    • InvalidTxSignatureException
    • InvalidTxUpdatedAddressesException
    • Transaction<T>
    • TxId
    • UnexpectedlyTerminatedTxRehearsalException

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
Object
SymmetricKey
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Libplanet.Crypto
Assembly: Libplanet.dll
Syntax
[Equals]
public class SymmetricKey

Constructors

| Improve this Doc View Source

SymmetricKey(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
ToByteArray()

Properties

| Improve this Doc View Source

ByteArray

An immutable Byte array encoding of this key.

Declaration
[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
ToByteArray()

Methods

| Improve this Doc View Source

Decrypt(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 nonSecret data. (See also Encrypt(Byte[], Byte[]) method's the second parameter, which is optional.) 0 by default.

Returns
Type Description
Byte[]

The plain data the ciphertext encrypted. It returns null if the ciphertext is invalid (this behavior will be eventually changed in the future to throw an exception instead).

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
Encrypt(Byte[], Byte[])
| Improve this Doc View Source

Encrypt(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 null, which means empty.

Returns
Type Description
Byte[]

A ciphertext that was encrypted from the message and can be decrypted with the same key. (Although the word “ciphertext” has the word “text”, a returned ciphertext is not a Unicode String, but a Byte array.)

See Also
Decrypt(Byte[], Int32)
| Improve this Doc View Source

ToByteArray()

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.

See Also
ByteArray
SymmetricKey(Byte[])
  • Improve this Doc
  • View Source
Back to top Copyright © 2019 Planetarium
Generated by DocFX