Versions in this module Expand all Collapse all v3 v3.5.0 Mar 1, 2023 Changes in this version + func AESEncryptFilesInDir(dir string, secret []byte, opts ...AESEncryptFilesInDirOption) (err error) + func AesDecrypt(secret []byte, encrypted []byte) ([]byte, error) + func AesEncrypt(secret []byte, cnt []byte) ([]byte, error) + func Base32Secret(key []byte) string + func CSR2Der(csr *x509.CertificateRequest) []byte + func CSRDer2Pem(CSRInDer []byte) (CSRInPem []byte) + func Cert2Der(cert *x509.Certificate) []byte + func Cert2Pem(cert *x509.Certificate) []byte + func CertDer2Pem(certInDer []byte) (certInPem []byte) + func DecodeES256SignByBase64(sign string) (r, s *big.Int, err error) + func DecodeES256SignByHex(sign string) (r, s *big.Int, err error) + func Der2CRL(crlDer []byte) (*x509.RevocationList, error) + func Der2CRLPkix(crlBytes []byte) (*pkix.CertificateList, error) + func Der2CSR(csrDer []byte) (*x509.CertificateRequest, error) + func Der2Cert(certInDer []byte) (*x509.Certificate, error) + func Der2Certs(certInDer []byte) ([]*x509.Certificate, error) + func Der2Prikey(prikeyDer []byte) (crypto.PrivateKey, error) + func Der2Pubkey(pubkeyDer []byte) (crypto.PublicKey, error) + func DeriveKey(rawKey []byte, newKeyLength int) (newKey []byte, err error) + func DeriveKeyByHKDF(rawKey, salt []byte, newKeyLength int) (newKey []byte, err error) + func DeriveKeyBySMHF(rawKey, salt []byte) (newKey []byte, err error) + func EncodeES256SignByBase64(r, s *big.Int) string + func EncodeES256SignByHex(r, s *big.Int) string + func FormatBig2Base64(b *big.Int) string + func FormatBig2Hex(b *big.Int) string + func GeneratePasswordHash(password []byte) ([]byte, error) + func GetPubkeyFromPrikey(priv crypto.PrivateKey) crypto.PublicKey + func HKDFWithSHA256(secret, salt, info []byte, results [][]byte) error + func HashSHA128String(val string) string + func HashSHA256String(val string) string + func HashXxhashString(val string) string + func MatchPrefix() func(o *oidContainsOption) error + func NewECDSAPrikey(curve ECDSACurve) (*ecdsa.PrivateKey, error) + func NewEd25519Prikey() (ed25519.PrivateKey, error) + func NewRSAPrikey(bits RSAPrikeyBits) (*rsa.PrivateKey, error) + func NewRSAPrikeyAndCert(rsaBits RSAPrikeyBits, opts ...X509CertOption) (prikeyPem, certDer []byte, err error) + func NewX509CRL(ca *x509.Certificate, prikey crypto.PrivateKey, seriaNumber *big.Int, ...) (crlDer []byte, err error) + func NewX509CSR(prikey crypto.PrivateKey, opts ...X509CSROption) (csrDer []byte, err error) + func NewX509Cert(prikey crypto.PrivateKey, opts ...X509CertOption) (certDer []byte, err error) + func NewX509CertByCSR(ca *x509.Certificate, prikey crypto.PrivateKey, csrDer []byte, ...) (certDer []byte, err error) + func OIDContains(oids []asn1.ObjectIdentifier, oid asn1.ObjectIdentifier, ...) bool + func ParseBase642Big(raw string) (*big.Int, error) + func ParseHex2Big(hex string) (b *big.Int, ok bool) + func Pem2CSR(csrInPem []byte) (*x509.CertificateRequest, error) + func Pem2Cert(certInPem []byte) (*x509.Certificate, error) + func Pem2Certs(certInPem []byte) ([]*x509.Certificate, error) + func Pem2Der(pemBytes []byte) (derBytes []byte, err error) + func Pem2Ders(pemBytes []byte) (dersBytes [][]byte, err error) + func Pem2Prikey(x509v8Pem []byte) (crypto.PrivateKey, error) + func Pem2Pubkey(pubkeyPem []byte) (crypto.PublicKey, error) + func Prikey2Der(key crypto.PrivateKey) ([]byte, error) + func Prikey2Pem(key crypto.PrivateKey) ([]byte, error) + func PrikeyDer2Pem(prikeyInDer []byte) (prikeyInPem []byte) + func Privkey2Signer(privkey crypto.PrivateKey) crypto.Signer + func Pubkey2Der(key crypto.PublicKey) ([]byte, error) + func Pubkey2Pem(key crypto.PublicKey) ([]byte, error) + func PubkeyDer2Pem(pubkeyInDer []byte) (prikeyInPem []byte) + func RSADecrypt(prikey *rsa.PrivateKey, cipher []byte) (plain []byte, err error) + func RSADer2Prikey(x509v1Der []byte) (*rsa.PrivateKey, error) + func RSAEncrypt(pubkey *rsa.PublicKey, plain []byte) (cipher []byte, err error) + func RSAPem2Prikey(x509v1Pem []byte) (*rsa.PrivateKey, error) + func ReadableOIDs(oids []asn1.ObjectIdentifier) (names []string) + func ReadablePkixName(name pkix.Name) map[string]any + func ReadableX509Cert(cert *x509.Certificate) (map[string]any, error) + func ReadableX509ExtKeyUsage(usages []x509.ExtKeyUsage) (usageNames []string) + func ReadableX509KeyUsage(usage x509.KeyUsage) (usageNames []string) + func Salt(length int) ([]byte, error) + func SecureCipherSuites(filter func(*tls.CipherSuite) bool) []uint16 + func SignByECDSAWithSHA256(priKey *ecdsa.PrivateKey, content []byte) (r, s *big.Int, err error) + func SignByECDSAWithSHA256AndBase64(priKey *ecdsa.PrivateKey, content []byte) (signature string, err error) + func SignByRSAWithSHA256(priKey *rsa.PrivateKey, content []byte) ([]byte, error) + func SignReaderByECDSAWithSHA256(priKey *ecdsa.PrivateKey, reader io.Reader) (r, s *big.Int, err error) + func SignReaderByRSAWithSHA256(priKey *rsa.PrivateKey, reader io.Reader) (sig []byte, err error) + func ValidatePasswordHash(hashedPassword, password []byte) bool + func VerifyByECDSAWithSHA256(pubKey *ecdsa.PublicKey, content []byte, r, s *big.Int) bool + func VerifyByECDSAWithSHA256AndBase64(pubKey *ecdsa.PublicKey, content []byte, signature string) (bool, error) + func VerifyByRSAWithSHA256(pubKey *rsa.PublicKey, content []byte, sig []byte) error + func VerifyCRL(ca *x509.Certificate, crl *x509.RevocationList) error + func VerifyCRLPkix(ca *x509.Certificate, crl *pkix.CertificateList) error + func VerifyCertByPrikey(certPem []byte, prikeyPem []byte) error + func VerifyReaderByECDSAWithSHA256(pubKey *ecdsa.PublicKey, reader io.Reader, r, s *big.Int) (bool, error) + func VerifyReaderByRSAWithSHA256(pubKey *rsa.PublicKey, reader io.Reader, sig []byte) error + func X509CertSubjectKeyID(pubkey crypto.PublicKey) ([]byte, error) + type AESEncryptFilesInDirOption func(*encryptFilesOption) error + func WithAESFilesInDirFileExt(ext string) AESEncryptFilesInDirOption + func WithAESFilesInDirFileSuffix(suffix string) AESEncryptFilesInDirOption + type AesReaderWrapper struct + func NewAesReaderWrapper(in io.Reader, key []byte) (*AesReaderWrapper, error) + func (w *AesReaderWrapper) Read(p []byte) (n int, err error) + type DHKX struct + func NewDHKX(optfs ...DHKXOptionFunc) (d *DHKX, err error) + func (d *DHKX) GenerateKey(peerPubKey []byte) ([]byte, error) + func (d *DHKX) PublicKey() []byte + type DHKXOptionFunc func(*dhkxOption) error + type DefaultX509CertSerialNumGenerator struct + func NewDefaultX509CertSerialNumGenerator() (*DefaultX509CertSerialNumGenerator, error) + func (g *DefaultX509CertSerialNumGenerator) SerialNum() int64 + type ECDSACurve string + const ECDSACurveP224 + const ECDSACurveP256 + const ECDSACurveP384 + const ECDSACurveP521 + type OTPAlgorithm string + const OTPAlgorithmSHA1 + type OTPArgs struct + AccountName string + Algorithm OTPAlgorithm + Base32Secret string + Digits uint + InitialCount int + IssuerName string + OtpType OTPType + PeriodSecs uint + func ParseOTPUri(uri string) (arg OTPArgs, err error) + func (a OTPArgs) Hasher() (*gotp.Hasher, error) + type OTPType string + const OTPTypeHOTP + const OTPTypeTOTP + type RSAPrikeyBits int + const RSAPrikeyBits2048 + const RSAPrikeyBits3072 + const RSAPrikeyBits4096 + type SignCSROption func(*signCSROption) error + func WithX509SerialNumGenerator(gen X509CertSerialNumberGenerator) SignCSROption + func WithX509SignCSRCRLs(crlEndpoint ...string) SignCSROption + func WithX509SignCSRExtKeyUsage(usage ...x509.ExtKeyUsage) SignCSROption + func WithX509SignCSRIsCA() SignCSROption + func WithX509SignCSRIsCRLCA() SignCSROption + func WithX509SignCSRKeyUsage(usage ...x509.KeyUsage) SignCSROption + func WithX509SignCSROCSPServers(ocsp ...string) SignCSROption + func WithX509SignCSRPolicies(policies ...asn1.ObjectIdentifier) SignCSROption + func WithX509SignCSRSeriaNumber(serialNumber *big.Int) SignCSROption + func WithX509SignCSRValidFor(validFor time.Duration) SignCSROption + func WithX509SignCSRValidFrom(validFrom time.Time) SignCSROption + type TOTP struct + func NewTOTP(arg OTPArgs) (*TOTP, error) + func (t *TOTP) Key() string + func (t *TOTP) KeyAt(at time.Time) string + func (t *TOTP) URI() string + type TOTPInterface interface + Key func() string + KeyAt func(at time.Time) string + URI func() string + type X509CRLOption func(*x509CRLOption) error + type X509CSROption func(*x509CSROption) error + func WithX509CSRCommonName(commonName string) X509CSROption + func WithX509CSRCountry(values ...string) X509CSROption + func WithX509CSRDNSNames(dnsNames ...string) X509CSROption + func WithX509CSREmailAddrs(emailAddresses ...string) X509CSROption + func WithX509CSRIPAddrs(ipAddresses ...net.IP) X509CSROption + func WithX509CSRLocality(l ...string) X509CSROption + func WithX509CSROrganization(organization ...string) X509CSROption + func WithX509CSROrganizationUnit(ou ...string) X509CSROption + func WithX509CSRPostalCode(codes ...string) X509CSROption + func WithX509CSRProvince(values ...string) X509CSROption + func WithX509CSRPublicKeyAlgorithm(pubAlg x509.PublicKeyAlgorithm) X509CSROption + func WithX509CSRSANS(sans ...string) X509CSROption + func WithX509CSRSignatureAlgorithm(sigAlg x509.SignatureAlgorithm) X509CSROption + func WithX509CSRStreetAddrs(addrs ...string) X509CSROption + func WithX509CSRSubject(subject pkix.Name) X509CSROption + func WithX509CSRURIs(uris ...*url.URL) X509CSROption + type X509CertOption func(*x509V3CertOption) error + func WithX509CertCRLs(crlEndpoint ...string) X509CertOption + func WithX509CertCommonName(commonName string) X509CertOption + func WithX509CertCountry(values ...string) X509CertOption + func WithX509CertDNSNames(dnsNames ...string) X509CertOption + func WithX509CertEmailAddrs(emailAddresses ...string) X509CertOption + func WithX509CertExtKeyUsage(usage ...x509.ExtKeyUsage) X509CertOption + func WithX509CertIPAddrs(ipAddresses ...net.IP) X509CertOption + func WithX509CertIsCA() X509CertOption + func WithX509CertIsCRLCA() X509CertOption + func WithX509CertKeyUsage(usage ...x509.KeyUsage) X509CertOption + func WithX509CertLocality(l ...string) X509CertOption + func WithX509CertOCSPServers(ocsp ...string) X509CertOption + func WithX509CertOrganization(organization ...string) X509CertOption + func WithX509CertOrganizationUnit(ou ...string) X509CertOption + func WithX509CertParent(parent *x509.Certificate) X509CertOption + func WithX509CertPolicies(policies ...asn1.ObjectIdentifier) X509CertOption + func WithX509CertPostalCode(codes ...string) X509CertOption + func WithX509CertProvince(values ...string) X509CertOption + func WithX509CertPubkey(pubkey crypto.PublicKey) X509CertOption + func WithX509CertPublicKeyAlgorithm(pubkeyAlg x509.PublicKeyAlgorithm) X509CertOption + func WithX509CertSANS(sans ...string) X509CertOption + func WithX509CertSeriaNumber(serialNumber *big.Int) X509CertOption + func WithX509CertSerialNumGenerator(gen X509CertSerialNumberGenerator) X509CertOption + func WithX509CertSignatureAlgorithm(sigAlg x509.SignatureAlgorithm) X509CertOption + func WithX509CertStreetAddrs(addrs ...string) X509CertOption + func WithX509CertURIs(uris ...*url.URL) X509CertOption + func WithX509CertValidFor(validFor time.Duration) X509CertOption + func WithX509CertValidFrom(validFrom time.Time) X509CertOption + func WithX509Subject(subject pkix.Name) X509CertOption + type X509CertSerialNumberGenerator interface + SerialNum func() int64 Other modules containing this package github.com/Laisky/go-utils/v4