go-cryptobin

module
v1.1.1013 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License: Apache-2.0

README

go-cryptobin

go-cryptobin is a go encrypt or decrypt library.

Go Reference

English | 中文

Desc

  • go-cryptobin library has encrypt / decrypt or sign / verify
  • sym encrypts(Aes/Des/TripleDes/SM4/Tea/Twofish/Xts)
  • encrypt mode(ECB/CBC/PCBC/CFB/NCFB/OFB/NOFB/CTR/GCM/CCM)
  • encrypt padding(NoPadding/ZeroPadding/PKCS5Padding/PKCS7Padding/X923Padding/ISO10126Padding/ISO97971Padding/ISO7816_4Padding/PBOC2Padding/TBCPadding/PKCS1Padding)
  • asym encrypts(Aes(RSA/SM2/ElGamal)
  • asym sign(RSA/RSA-PSS/DSA/ECDSA/EC-GDSA/EdDSA/SM2/ElGamal/ED448/Gost)
  • default setting Aes, ECB, NoPadding

Env

  • Go >= 1.20

Download

go get -u github.com/deatil/go-cryptobin

Get Starting

package main

import (
    "fmt"

    "github.com/deatil/go-cryptobin/cryptobin/crypto"
)

func main() {
    // encrypt
    cypten := crypto.
        FromString("useData").
        SetKey("dfertf12dfertf12").
        SetIv("dfertf12dfertf12").
        Aes().
        CBC().
        PKCS7Padding().
        Encrypt().
        ToBase64String()

    // decrypt
    cyptde := crypto.
        FromBase64String("i3FhtTp5v6aPJx0wTbarwg==").
        SetKey("dfertf12dfertf12").
        SetIv("dfertf12dfertf12").
        Aes().
        CBC().
        PKCS7Padding().
        Decrypt().
        ToString()

    // i3FhtTp5v6aPJx0wTbarwg==
    fmt.Println("encrypt res:", cypt)
    fmt.Println("decrypt res:", cyptde)
}

Struct Desc

  • default setting Aes, ECB, NoPadding. default not use padding, input need n*16 length, not right length need other padding
// encrypt data
cypt := crypto.
    FromString("useData5useData5").
    SetKey("dfertf12dfertf12").
    Encrypt().
    ToBase64String()
// decrypt data
cyptde := crypto.
    FromBase64String("eZf7c3fcwKlmrqogiEHbJg==").
    SetKey("dfertf12dfertf12").
    Decrypt().
    ToString()
  • Use Desc
// Code
// Tips: SetKey,SetIv,Encrypt Type,Mode,Padding at `Action Type` before can move sorts
ret := crypto.
    FromString("string"). // Data Src
    SetKey("key_string"). // Set Key
    SetIv("iv_string").   // Set Iv
    Aes().                // Encrypt Type
    CBC().                // Mode
    PKCS7Padding().       // Padding
    Encrypt().            // Action Type
    ToBase64String()      // To Data Type

PKG Funcs

  • Data From: FromBytes(data []byte), FromString(data string), FromBase64String(data string), FromHexString(data string)

  • Set Key: SetKey(data string), WithKey(key []byte)

  • Set IV: SetIv(data string), WithIv(iv []byte)

  • Encrypt Type: Aes(), Des(), TripleDes(), Twofish(), Blowfish(), Tea(rounds ...int), Xtea(), Cast5(), RC4(), Idea(), SM4(), Chacha20(counter ...uint32), Chacha20poly1305(additional ...[]byte), Xts(cipher string, sectorNum uint64)

  • Encrypt Mode: ECB(), CBC(), PCBC(), CFB(), OFB(), CTR(), GCM(additional ...[]byte), CCM(additional ...[]byte)

  • Paddings: NoPadding(), ZeroPadding(), PKCS5Padding(), PKCS7Padding(), X923Padding(), ISO10126Padding(), ISO7816_4Padding(),ISO97971Padding(),PBOC2Padding(), TBCPadding(), PKCS1Padding(bt ...string)

  • Action Type: Encrypt(), Decrypt(), FuncEncrypt(f func(Cryptobin) Cryptobin), FuncDecrypt(f func(Cryptobin) Cryptobin)

  • To Data Type: ToBytes(), ToString(), ToBase64String(), ToHexString()

  • more data docs

LICENSE

  • The library LICENSE is Apache2, using the library need keep the LICENSE.

Directories

Path Synopsis
ber
cipher
ascon
Package ascon implements the ASCON AEAD cipher.
Package ascon implements the ASCON AEAD cipher.
des
e2
hc
kcipher2
Package kcipher2 implements the KCipher-2 stream cipher
Package kcipher2 implements the KCipher-2 stream cipher
lea
misty1
Package misty1 implements the MISTY1 cipher
Package misty1 implements the MISTY1 cipher
rc2
rc5
rc6
sm4
spritz
Package spritz implements the Spritz stream-cipher
Package spritz implements the Spritz stream-cipher
threefish
Package threefish implements the Threefish tweakable block cipher.
Package threefish implements the Threefish tweakable block cipher.
twine
Package twine implements the TWINE lightweight block cipher
Package twine implements the TWINE lightweight block cipher
cryptobin
ca
dsa
ed448
// 生成公钥私钥 / CreateKey: obj := ed448.
// 生成公钥私钥 / CreateKey: obj := ed448.
rsa
sm2
ssh
key
elliptic
base_elliptic
Package `base_elliptic` implements Elliptic curves over binary fields
Package `base_elliptic` implements Elliptic curves over binary fields
bign/curve/fiat
Code generated by generate.go.
Code generated by generate.go.
bitcurves
Package bitelliptic implements several Koblitz elliptic curves over prime fields.
Package bitelliptic implements several Koblitz elliptic curves over prime fields.
kg
s256
Package secp256k1 implements the standard secp256k1 elliptic curve over prime fields.
Package secp256k1 implements the standard secp256k1 elliptic curve over prime fields.
secp256k1
Package secp256k1 implements the standard secp256k1 elliptic curve over prime fields.
Package secp256k1 implements the standard secp256k1 elliptic curve over prime fields.
tom
gm
sm2
sm9
zuc
hash
cmac/aes
Package aes implements the CMAC MAC with the AES.
Package aes implements the CMAC MAC with the AES.
md2
pmac
PMAC message authentication code, defined in http://web.cs.ucdavis.edu/~rogaway/ocb/pmac.pdf
PMAC message authentication code, defined in http://web.cs.ucdavis.edu/~rogaway/ocb/pmac.pdf
pmac/aes
Package aes implements the PMAC MAC with the AES.
Package aes implements the PMAC MAC with the AES.
rabin
Package rabin implements Rabin hashing (fingerprinting).
Package rabin implements Rabin hashing (fingerprinting).
sm3
kdf
argon2
Package argon2 implements the key derivation function Argon2.
Package argon2 implements the key derivation function Argon2.
CFB (Cipher Feedback) Mode.
CFB (Cipher Feedback) Mode.
ccm
eax
mgm
ocb
siv
passhash
ber
pubkey
dsa
ed448
Package ed448 implements the Ed448 signature algorithm defined in RFC 8032.
Package ed448 implements the Ed448 signature algorithm defined in RFC 8032.
kg
lms
rsa
x25519
Package x25519 implements the X25519 Elliptic Curve Diffie-Hellman algorithm.
Package x25519 implements the X25519 Elliptic Curve Diffie-Hellman algorithm.
x448
Package x448 implements the X448 Elliptic Curve Diffie-Hellman algorithm.
Package x448 implements the X448 Elliptic Curve Diffie-Hellman algorithm.
rand
tool
pem
xor

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL