Public key and private key example

Public-key cryptography (PKC) is a technology often used to validate the authenticity of data using asymmetric encryption. PKC was first used primarily to encrypt and decrypt messages in traditional computing. Cryptocurrencies now use this technology to encrypt and decrypt transactions. Without PKC, the technology underpinning cryptocurrencies would be practically impossible.

The key to PKC is “trapdoor functions,” one-way mathematical functions that are easy to solve in one way, but nearly impossible to crack in the reverse. While it might be possible, it would likely take a supercomputer — and thousands of years — to reverse engineer these functions.

A public key allows you to receive cryptocurrency transactions. It’s a cryptographic code that’s paired to a private key. While anyone can send transactions to the public key, you need the private key to “unlock” them and prove that you are the owner of the cryptocurrency received in the transaction. The public key that can receive transactions is usually an address, which is simply a shortened form of your public key.

Therefore, you can freely share your public key without worry. You may have seen donation pages for content-creators or charities with the public keys for their crypto addresses online. While anyone can donate, you’d need the private key to unlock and access the donated funds.

Here is one crucial piece of advice to remember: Never share your private key with anyone. A private key gives you the ability to prove ownership or spend the funds associated with your public address. A private key can take many forms:

  • 256 character long binary code

  • 64 digit hexadecimal code

  • QR code

  • Mnemonic phrase

Regardless of its form, a private key is an astronomically large number, and it’s large for a good reason. While you can generate a public key with a private key, doing the opposite is practically impossible because of the one-way “trapdoor” function. You can have any number of public keys connected to a private key.

  • What Does It Mean to “Digitally Sign” a Transaction?

  • For a transaction on the blockchain to be complete, it needs to be signed. The steps for someone to send you a transaction are:

    1. A transaction is encrypted using a public key. The transaction can only be decrypted by the accompanying private key.  

    2. Next, the transaction is signed using the private key, which proves that the transaction hasn’t been modified. The digital signature is generated through combining the private key with the data being sent in the transaction. 

    3. Finally, the transaction can be verified as authentic using the accompanying public key.

    You digitally sign a transaction to prove you’re the owner of the funds. Nodes check and authenticate transactions automatically. Any unauthenticated transactions get rejected by the network. An authentic, mined transaction on the blockchain is irreversible.

  • Where Are My “Private Keys?”

  • Your private keys are in a cryptocurrency wallet, which is typically mobile or desktop software or a specialized hardware device. Your private keys are not on the cryptocurrency blockchain network. If you keep cryptocurrency on an exchange, then the exchange is the custodian of your private keys; you’re trusting it with your keys in the same way you’d trust a bank’s vault to hold your gold.

    If you transfer your cryptocurrency from an exchange to a non-custodial wallet, then you are in control of your keys. Because of the configuration and functionality of cryptocurrency wallets, you’ll likely never handle the private keys directly as wallets generally manage them for you automatically. Typically, you’re given a seed phrase that encodes your private keys as a back-up.

  • Public and Private Keys Control Your Crypto

  • How public and private keys work together is fundamental to understanding how cryptocurrency transactions function. When you say you have cryptocurrency, what you’re really saying is you have a private key that proves ownership of that cryptocurrency. Since it’s stored on the blockchain, anyone can verify you as the owner with your public key.

    The choice of “holding your own keys” or trusting a custodian depends on your philosophy, risk-tolerance, and a host of other factors. If you hold your own private keys, consider modern HD wallets, which can do a great job of managing your private keys, and remember to never share them. If you choose a custodial solution like an exchange, make sure you choose a trusted, reputable company that places a high emphasis on security and regulation.

    A public key and a private key constitute a key pair, which is generated by using an encryption algorithm. A key pair is used for asymmetric encryption. A public key is used to encrypt sessions and verify digital signatures, and its paired private key is used to decrypt the session data. This ensures the security of data transmission. A public key is disclosed to the public, and its paired private key is private to the user that creates the key pair.

    A key pair that is generated by using an encryption algorithm is unique around the world. If you use a key in a key pair to encrypt a piece of data, the data can be decrypted only by using the other key in the key pair. For example, data that is encrypted by using a public key can be decrypted only by using its paired private key. Data that is encrypted by using a private key can be decrypted only by using its paired public key.

    How an SSL certificate works

    SSL certificates adopt public key cryptography, which uses a key pair to encrypt and decrypt data. Each user creates a private key that is not disclosed to anyone for decryption and signature. The user also creates a public key and discloses the key to a group of users for encryption and signature verification.

    Only the key owner can use the private key to encrypt a document, which generates a digital signature.

    An SSL certificate is a document that is digitally signed by a certificate authority (CA). The document contains information about a public key and the owner of the public key. A certificate must contain a public key, a certificate name, and a digital signature that is provided by a CA. A digital certificate is valid for only a specific period of time.

    For more information about private keys, see How does Certificate Management Service protect private keys?

    Create a private key

    Certificate Management Service has the following requirements for the length of a private key and the encryption algorithm that you use to create a private key:

    • The Rivest-Shamir-Adleman (RSA) algorithm must be used.
    • The private key must be at least 2,048 bits in length.

    You can use one of the following methods to create a private key:

    • Use OpenSSL to generate a private key
      1. Download the latest installation package for OpenSSL from the OpenSSL official website at OpenSSL.

        Note The version of OpenSSL must be 1.0.1g or later.

      2. After OpenSSL is installed, run the openssl genrsa -out myprivate.pem 2048 command on the command line to generate a private key file. The private key file is named myprivate.pem. The private key is 2,048 bits in length.
    • Use Keytool to generate and export a private key

      Keytool is a key management tool that comes with JDK. Keytool allows you to create keystore files in the JKS format for certificates. To obtain Keytool, you can download JDK from the Java official website at Java Downloads.

      By default, the public keys and private keys that are created by using Keytool cannot be exported. You can export a private key only from a .keystore file that is created. For more information about how to export a private key from a .keystore file, see How do I convert the format of a certificate?

      In the exported file, the private key is enclosed by the following lines of code:

      -----BEGIN RSA PRIVATE KEY-----
      ......
      -----END RSA PRIVATE KEY-----

      Or

      -----BEGIN PRIVATE KEY-----
      ......
      -----END PRIVATE KEY-----

      Note We recommend that you keep your private key confidential. If the private key is lost or becomes corrupt, you can no longer use its paired public key or the digital certificate.

      What is difference between public key and private key?

      To conclude, private keys can be used for both encryption and decryption, while Public keys are used only for the purpose of encrypting the sensitive data. Private keys are shared between the sender and the receiver, whereas public keys can be freely circulated among multiple users.

      What are examples of public key cryptography?

      Examples.
      Diffie–Hellman key exchange protocol..
      DSS (Digital Signature Standard), which incorporates the Digital Signature Algorithm..
      ElGamal..
      Elliptic-curve cryptography. ... .
      Various password-authenticated key agreement techniques..
      Paillier cryptosystem..
      RSA encryption algorithm (PKCS#1).
      Cramer–Shoup cryptosystem..

      Where is public and private key used?

      Public keys and private keys are the working parts of Public-key cryptography. Together, they encrypt and decrypt data that resides or moves in a network. The public key is truly public and can be shared widely while the private key should be known only to the owner.

      What is your public key?

      A public key is a cryptographic code that allows users to receive cryptocurrencies into their accounts. The public key and the private key are the tools required to ensure the security of the crypto economy.