• Overview
  • 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
    • ActionTypeAttribute
    • IAccountStateDelta
    • IAction
    • IActionContext
    • IRandom
    • MissingActionTypeException
    • PolymorphicAction<T>
    • RandomExtension
    • UnexpectedlyTerminatedActionException
  • Libplanet.Blockchain
    • BlockChain<T>
    • BlockChain<T>.TipChangedEventArgs
    • IncompleteBlockStatesException
    • MineBlockEventArgs<T>
  • Libplanet.Blockchain.Policies
    • BlockPolicy<T>
    • IBlockPolicy<T>
  • Libplanet.Blocks
    • Block<T>
    • InvalidBlockDifficultyException
    • InvalidBlockException
    • InvalidBlockHashException
    • InvalidBlockIndexException
    • InvalidBlockNonceException
    • InvalidBlockPreviousHashException
    • InvalidBlockTimestampException
    • InvalidGenesisBlockException
  • Libplanet.Crypto
    • CryptoConfig
    • DefaultCryptoBackend
    • ICryptoBackend
    • InvalidCiphertextException
    • PrivateKey
    • PublicKey
    • SymmetricKey
  • Libplanet.KeyStore
    • IncorrectPassphraseException
    • InvalidKeyJsonException
    • KeyJsonException
    • MismatchedAddressException
    • ProtectedPrivateKey
    • UnsupportedKeyJsonException
  • Libplanet.KeyStore.Ciphers
    • Aes128Ctr
    • ICipher
  • Libplanet.KeyStore.Kdfs
    • IKdf
    • Pbkdf2<T>
    • Scrypt
  • Libplanet.Net
    • ActionExecutionState
    • BlockDownloadState
    • BoundPeer
    • DifferentAppProtocolVersionException
    • DifferentProtocolVersionEventArgs
    • IceServer
    • IceServerException
    • InvalidMessageException
    • NoSwarmContextException
    • Peer
    • PeerNotFoundException
    • PeerState
    • PreloadBlockDownloadFailEventArgs
    • PreloadState
    • StateDownloadState
    • Swarm<T>
    • SwarmException
  • Libplanet.Net.Protocols
    • PeerDiscoveryException
  • Libplanet.Serialization
    • SerializationInfoExtension
  • Libplanet.Store
    • BaseIndex<TKey, TVal>
    • BaseStore
    • BlockSet<T>
    • ChainIdNotFoundException
    • DefaultStore
    • IStore
    • StoreExtension
    • TransactionSet<T>
  • Libplanet.Tx
    • InvalidTxException
    • InvalidTxIdException
    • InvalidTxNonceException
    • InvalidTxPublicKeyException
    • InvalidTxSignatureException
    • InvalidTxUpdatedAddressesException
    • Transaction<T>
    • TxId

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
Namespace: Libplanet.Crypto
Assembly: Libplanet.dll
Syntax
public class SymmetricKey : object

Constructors

| Improve this Doc View Source

SymmetricKey(Byte[])

Creates a SymmetricKey instance from the given 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 array that encodes an AES-GCM symmetric key.

Remarks

A valid array for a SymmetricKey can be encoded using ToByteArray() method.

See Also
ToByteArray()

Properties

| Improve this Doc View Source

ByteArray

An immutable array encoding of this key.

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
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
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 string, not a Unicode .

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
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 , but a array.)

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

ToByteArray()

Gets a mutable array which encodes this key.

Declaration
public byte[] ToByteArray()
Returns
Type Description
Byte[]

A new mutable 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–2020 Planetarium