# Account Cryptography

IoTeX uses cryptographic techniques to secure its accounts and ensure the integrity and authenticity of transactions. Specifically, IoTeX account generation and digital signature are based on the same cryptographic schemes as Ethereum.

Here are the key components of IoTeX's account cryptography:

**Elliptic Curve Digital Signature Algorithm (ECDSA):****Private Key:**IoTeX accounts are secured using private keys, which are 256-bit random numbers. The private key is known only to the account owner and is used to sign transactions.**Public Key:**The public key is derived from the private key using the secp256k1 elliptic curve. The public key is then used to generate the IoTeX address, which can be both in the format of an Ethereum address (starting with "0x...") or a native IoTeX address (starting with "io1...").

**IoTeX Address:**The IoTeX address can be generated like an Ethereum address, derived from the public key by taking the last 20 bytes of the Keccak-256 hash of the public key. This address is a unique identifier for the account on the IoTeX network.

-> Learn here how to construct the IoTeX address in native format

**Keccak-256 Hash Function:**IoTeX uses the Keccak-256 cryptographic hash function (often referred to as SHA-3) for various purposes, including generating addresses from public keys and ensuring data integrity.

**Digital Signatures:**Transactions in IoTeX are signed with the account's private key using ECDSA. The digital signature ensures that the transaction was created by the account owner and has not been altered. Nodes in the network can verify the signature using the corresponding public key.

**Nonce:**Each account has a nonce, which is a counter that keeps track of the number of transactions sent from the account. The nonce prevents replay attacks by ensuring that each transaction can only be processed once.

**Account Encryption:**While not a part of the core protocol, encryption is often used to protect private keys. Wallets and other storage solutions typically encrypt private keys to prevent unauthorized access.

**Secure Key Storage:**Hardware wallets and other secure storage solutions use additional cryptographic techniques to protect private keys from being compromised.

## Private Key

In IoTeX, the account Private Key is generated as 64 random hex characters, e.g.:

and the corresponding **Public Key **is derived from the private key using ECDSA with the secp256k1 curve, which is the same as Ethereum.

Given a signed message, you can recover the public key of the signing account using Ecrecover, also defined in solidity for signature verification in smart contracts.

### Native Address Construction

An IoTeX native representation of an account address looks like:

and it can be constructed starting from the private key using the following steps:

**1. Generate a random private key as 64 random hex characters**

**2. Calculate the corresponding public key using secp256k1 elliptic curve**

**3. Apply ****keccak256**** hash function to the public key, excluding the first byte:**

**4. Take the last 20 bytes of the hash**

which is the "byte representation" of the address

**5. Convert the byte representation to 5-bit encoding (base32):**

See a go lang implementation for the 5-bit conversion implementation or a nodejs package (use `toWords()`

to convert a bytes array into 5-bit words).

**6. Apply the ****bech32 ****encoding on the 5-bit payload with the ****io**** prefix to obtain the address:**

See a go lang implementation for the bech32 encoding implementation or a nodejs package (use `encode`

to encode 5-bit words with a prefix).

Last updated