Skip to content

Commit

Permalink
fix(be): base64 for encrypted private key
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Aug 30, 2021
1 parent 7443671 commit bb3f560
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions db/AccessKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (key *AccessKey) EncryptSecret() error {
return err
}

secret := string(gcm.Seal(nonce, nonce, plaintext, nil))
secret := base64.StdEncoding.EncodeToString(gcm.Seal(nonce, nonce, plaintext, nil))

key.Secret = &secret

Expand All @@ -83,14 +83,19 @@ func (key AccessKey) DecryptSecret() (string, error) {

ciphertext := []byte(*key.Secret)

if ciphertext[len(ciphertext) - 1] == '\n' { // not encrypted string
if ciphertext[len(*key.Secret) - 1] == '\n' { // not encrypted string
return *key.Secret, nil
}

if util.Config.AccessKeyEncryption == "" { // do not decrypt if secret key not specified
return *key.Secret, nil
}

ciphertext, err := base64.StdEncoding.DecodeString(*key.Secret)
if err != nil {
return "", err
}

encryption, err := base64.StdEncoding.DecodeString(util.Config.CookieEncryption)
if err != nil {
return "", err
Expand Down

0 comments on commit bb3f560

Please sign in to comment.