// GenerateRSAPems generates RSA key pair and the PEM encoding of them.
GenerateRSAPems generates RSA key pair and the PEM encoding of them.
// GenerateRSAPems generates RSA key pair and the PEM encoding of them .
func GenerateRSAPems(size int) (private, public []byte, err error) {
	privateKey, err := rsa.GenerateKey(rand.Reader, size)
	if err != nil {
		return
	}
	err = privateKey.Validate()
	if err != nil {
		return
	}
	publicBytes, err := x509.MarshalPKIXPublicKey(&privateKey.PublicKey)
	if err != nil {
		return
	}
	public = pem.EncodeToMemory(
		&pem.Block{
			Type:  "PUBLIC KEY",
			Bytes: publicBytes,
		},
	)
	privateBytes, err := x509.MarshalPKCS8PrivateKey(privateKey)
	if err != nil {
		return
	}
	private = pem.EncodeToMemory(
		&pem.Block{
			Type:  "PRIVATE KEY",
			Bytes: privateBytes,
		},
	)
	return
}
func GenerateRSAPems ( size int ) ( private , public [ ] byte , err error ) { privateKey , err := rsa . GenerateKey ( rand . Reader , size ) if err != nil { return } err = privateKey . Validate ( ) if err != nil { return } publicBytes , err := x509 . MarshalPKIXPublicKey ( & privateKey . PublicKey ) if err != nil { return } public = pem . EncodeToMemory ( & pem . Block { Type : " " , Bytes : publicBytes , } , ) privateBytes , err := x509 . MarshalPKCS8PrivateKey ( privateKey ) if err != nil { return } private = pem . EncodeToMemory ( & pem . Block { Type : " " , Bytes : privateBytes , } , ) return }
GenerateRSAPems generates RSA key pair and the PEM encoding of them.
GenerateRSAPems generates RSA key pair and the PEM encoding of them .