Documentation ¶
Index ¶
- Constants
- Variables
- func AESDecryptCBC(keySt []byte, ciphertext []byte) (decrypted []byte, err error)
- func AESEncryptCBC(keyByte []byte, plaintext []byte) ([]byte, error)
- func AESGenerate256Key() (key []byte, err error)
- func RSADecryptOAEP(ciphertext, privateKey []byte) (output []byte, err error)
- func RSAEncryptOAEP(publicKey, data []byte) (output []byte, err error)
- func RSASignMessage(message []byte, signKey []byte) (signature string, err error)
- func RSAVerifySignature(sig string, message []byte, verifyKey []byte) error
- type CertOption
- type HASH
- type Keypair
- type OpenSSL
- func (ssl *OpenSSL) Certificate() *x509.Certificate
- func (ssl *OpenSSL) ExportP12(pwd string, output string) error
- func (ssl *OpenSSL) GenRSA(bits uint32, args ...string) (err error)
- func (ssl *OpenSSL) ImportP12(data []byte, pwd string) error
- func (ssl *OpenSSL) MakeCertificate(opt *CertOption) error
- func (ssl *OpenSSL) PrivateKey() *rsa.PrivateKey
Constants ¶
const (
RSA2048Bits uint32 = 1 << 11
)
Variables ¶
var ( CertOptDefault = CertOption{ Issuer: pkix.Name{ Country: []string{"VN"}, Organization: []string{}, OrganizationalUnit: []string{}, CommonName: "", }, SubjectNameObject: pkix.Name{ Country: []string{"VN"}, Organization: []string{"ioVN Co., Ltd"}, OrganizationalUnit: []string{}, Locality: []string{}, Province: []string{"Some-State"}, CommonName: "", }, MakeExpires: func() time.Time { return time.Now().AddDate(1, 0, 0) }, } )
Functions ¶
func AESDecryptCBC ¶
AESDecryptCBC decrypt aes in CBC mode and remove pkcs7 padding.
func AESEncryptCBC ¶
AESEncryptCBC padding with pkcs7 before encrypt with CBC mode.
func AESGenerate256Key ¶
AESGenerate256Key : generate an 256 bits AES key.
func RSADecryptOAEP ¶
RSADecryptOAEP decrypts ciphertext using RSA-OAEP, privateKey in PKCS#8 encoded form.
func RSAEncryptOAEP ¶
RSAEncryptOAEP : encrypts the given message with RSA-OAEP, publicKey in DER-encoded PKIX format.
func RSASignMessage ¶
RSASignMessage sign message, return base64 signature
Types ¶
type CertOption ¶
type OpenSSL ¶
type OpenSSL struct {
// contains filtered or unexported fields
}
func (*OpenSSL) Certificate ¶
func (ssl *OpenSSL) Certificate() *x509.Certificate
Certificate : Get *x509.Certificate object.
Note: Must call after GenRSA() or ImportP12() function
func (*OpenSSL) ExportP12 ¶
ExportP12 : save keyPair to pkcs12 type.
Note: Must call after GenRSA() or ImportP12() function
func (*OpenSSL) GenRSA ¶
GenRSA : This command generates an RSA private key.
$ openssl genrsa -out private.pem 2048
func (*OpenSSL) ImportP12 ¶
ImportP12 with private.p12
$ openssl pkcs12 -in private.p12 -clcerts -nokeys -out PublicKey.cer
$ openssl pkcs12 -in private.p12 -nodes -nocerts | openssl rsa -out PrivateKey.key
func (*OpenSSL) MakeCertificate ¶
func (ssl *OpenSSL) MakeCertificate(opt *CertOption) error
MakeCertificate : Make *x509.Certificate value for OpenSSL object.
Note: Must call after GenRSA() function
func (*OpenSSL) PrivateKey ¶
func (ssl *OpenSSL) PrivateKey() *rsa.PrivateKey
PrivateKey : Get *rsa.PrivateKey object.
Note: Must call after GenRSA() or ImportP12() function