Browse Source

Merge commit 'cc941576830d85880737d386064b721156dfe82b' into wip-main-ui

wip-main-ui
Jaeha Choi 2 months ago
parent
commit
ac56f49368
Signed by: Jaeha.Choi GPG Key ID: D6133D1D117FF503
  1. 15
      pkg/cryptography/rsa.go

15
pkg/cryptography/rsa.go

@ -7,6 +7,7 @@ import (
"crypto/sha256"
"crypto/x509"
"encoding/pem"
"errors"
"github.com/jaeha-choi/Proj_Coconut_Utility/log"
"io/ioutil"
"os"
@ -17,6 +18,8 @@ const (
rsaKeyBitSize = 4096
)
var NoPemBlock = errors.New("[]byte does not contain public pem block")
// createRSAKey creates RSA keys with bitSize.
func createRSAKey(bitSize int) (privKey *rsa.PrivateKey, err error) {
reader := rand.Reader
@ -173,6 +176,18 @@ func PemToSha256(pubBlock *pem.Block) []byte {
return hash[:]
}
// BytesToPemFile writes pemBytes to fileName in PEM block format.
func BytesToPemFile(pemBytes []byte, fileName string) (err error) {
block, _ := pem.Decode(pemBytes)
if block == nil || block.Type != "RSA PUBLIC KEY" {
return NoPemBlock
}
if err = os.WriteFile(fileName, block.Bytes, 0x600); err != nil {
return err
}
return nil
}
// EncryptSignMsg encrypts key for symmetric encryption with receiver's pubic key,
// and sign hashed symmetric encryption key with sender's private key.
func EncryptSignMsg(msg []byte, receiverPubKey *rsa.PublicKey, senderPrivKey *rsa.PrivateKey) (

Loading…
Cancel
Save