RSA To “Go” …

--

The method described in this article is here.

The RSA method was published in August 1977, and it is still going strong. While it can be slow — and where Shor illustrated that the 768-bit version can be easily cracked by quantum computes — it still exists within our PKI world, and also within secure email systems. So let’s use the Go programming language, and encrypt and decrypt a simple message.

RSA uses a public key and a private key, and where we can encrypt with the public key and decrypt with the private key. In this case Alice will send an encrypted message to Bob, so Alice needs to use Bob’s public key to encrypt the message, and then he will use his private key to decrypt it. We would typically use 2,048 bits are more, but, in this example, we will use 1,024 bit keys:

package mainimport (
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"fmt"
"flag"
"crypto/x509"
"encoding/pem"
)func ExportPublicKeyAsPemStr(pubkey *rsa.PublicKey) string {
pubkey_pem := string(pem.EncodeToMemory(&pem.Block{Type: "RSA PUBLIC KEY",Bytes: x509.MarshalPKCS1PublicKey(pubkey)}))
return pubkey_pem
}
func ExportPrivateKeyAsPemStr(privatekey *rsa.PrivateKey) string {
privatekey_pem := string(pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY",Bytes…

--

--

Prof Bill Buchanan OBE FRSE
ASecuritySite: When Bob Met Alice

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. Based in Edinburgh. Old World Breaker. New World Creator. Building trust.