rsa-asymmetric-cryptography

command
v0.0.0-...-a2a1f02 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2020 License: MIT Imports: 9 Imported by: 0

README

rsa-asymmetric-cryptography example

Encrypt a message using a public key. Decrypt the message using a private key. Key pair generated using the crypto/rsa standard package (RSA is a cryptosystem for public key encryption).

Refer to the crypto/rsa package for more info.

I added a digital signature to this example rsa-asymmetric-cryptography-with-digital-signature.

GitHub Webpage

OVERVIEW

RSA is a cryptosystem for public-key encryption, and is used for securing sensitive data over unsecured networks.

This illustration may help,

IMAGE - rsa-asymmetric-cryptography.jpg - IMAGE

RUN

go run rsa-asymmetric-cryptography.go <FILENAME>
go run rsa-asymmetric-cryptography.go test.txt

HOW IT WORKS

Generate rsa keys,

// GENERATE PRIVATE & PUBLIC KEY PAIR
privateKeyRaw, err := rsa.GenerateKey(rand.Reader, 2048)

// EXTRACT PUBLIC KEY
publicKeyRaw := &privateKeyRaw.PublicKey

Take a message plainText and encrypt it,

// ENCRYPT
cipherTextByte, err := rsa.EncryptOAEP(
    hash,
    rand.Reader,
    publicKeyRaw,
    plainTextByte,
    label,
)

Take a message cipherText and decrypt it,

// DECRYPT DATA
plainTextByte, err := rsa.DecryptOAEP(
    hash,
    rand.Reader,
    privateKeyRaw,
    cipherTextByte,
    label,
)

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL