Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions internal/crypto/b64.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@ package crypto

import "encoding/base64"

// EncryptB64 encrypts data into base64 string
func EncryptB64(text string) string {
// EncodeB64 encodes data to a base64 string.
func EncodeB64(text string) string {
return base64.StdEncoding.EncodeToString([]byte(text))
}

// DecryptB64 decrypts from base64 string to readable string
func DecryptB64(s string) (string, error) {
// DecodeB64 decodes a base64 string back to plaintext.
func DecodeB64(s string) (string, error) {
data, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return "", err
}
return string(data), nil
}

// EncryptB64 is a deprecated alias for EncodeB64.
func EncryptB64(text string) string {
return EncodeB64(text)
}

// DecryptB64 is a deprecated alias for DecodeB64.
func DecryptB64(s string) (string, error) {
return DecodeB64(s)
}
7 changes: 5 additions & 2 deletions internal/crypto/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// NewRSAKey to generate new RSA Key if env is not set
// returns key instance, private key string, public key string, jwk string, error
func NewRSAKey(algo, keyID string) (*rsa.PrivateKey, string, string, string, error) {
key, err := rsa.GenerateKey(rand.Reader, 2048)
key, err := rsa.GenerateKey(rand.Reader, 4096)
if err != nil {
return nil, "", "", "", err
}
Expand Down Expand Up @@ -130,7 +130,10 @@ func EncryptRSA(message string, key rsa.PublicKey) (string, error) {
}

func DecryptRSA(cipherText string, privateKey rsa.PrivateKey) (string, error) {
ct, _ := base64.StdEncoding.DecodeString(cipherText)
ct, err := base64.StdEncoding.DecodeString(cipherText)
if err != nil {
return "", err
}
label := []byte("OAEP Encrypted")
rng := rand.Reader
plaintext, err := rsa.DecryptOAEP(sha256.New(), rng, &privateKey, ct, label)
Expand Down