Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PKCS8PrivateKey ¶
type PKCS8PrivateKey struct {
PrivateKey *rsa.PrivateKey
}
func ParsePKCS8PrivateKey ¶
func ParsePKCS8PrivateKey(privateKey []byte) (private PKCS8PrivateKey, err error)
func (PKCS8PrivateKey) RsaDecryptPKCS1v15 ¶
func (r PKCS8PrivateKey) RsaDecryptPKCS1v15(ciphertext []byte) (source []byte, err error)
type PKIXPublicKey ¶
func ParsePKIXPublicKey ¶
func ParsePKIXPublicKey(publicKey []byte) (public PKIXPublicKey, err error)
func (PKIXPublicKey) RsaEncryptPKCS1v15 ¶
func (r PKIXPublicKey) RsaEncryptPKCS1v15(source []byte) (ciphertext []byte, err error)
type RsaKeyPKCS8 ¶
func GenRsaKeyPKCS8 ¶
func GenRsaKeyPKCS8(keySize uint) (rsaKey RsaKeyPKCS8, err error)
GenRsaKey(1024)
Example ¶
package main import ( xbase64 "github.com/goclub/base64" xcrypto "github.com/goclub/crypto" xerr "github.com/goclub/error" "log" ) func main() { var err error defer func() { if err != nil { xerr.PrintStack(err) } }() rsaKey, err := xcrypto.GenRsaKeyPKCS8(1024) if err != nil { return } log.Print("rsaKey.PublicKeyBytes:\n", string(rsaKey.PublicKeyBytes)) log.Print("rsaKey.PrivateKey:\n", string(rsaKey.PrivateKeyBytes)) publicKey, err := xcrypto.ParsePKIXPublicKey(rsaKey.PublicKeyBytes) if err != nil { return } cipherText, err := publicKey.RsaEncryptPKCS1v15([]byte("goclub.run")) if err != nil { return } log.Print("base64(cipherText):\n", string(xbase64.EncodeRawStd(cipherText))) privateKey, err := xcrypto.ParsePKCS8PrivateKey(rsaKey.PrivateKeyBytes) if err != nil { return } source, err := privateKey.RsaDecryptPKCS1v15(cipherText) if err != nil { return } log.Print("source:\n", string(source)) // goclub.run }
Output:
Click to show internal directories.
Click to hide internal directories.