[go-cryptobin](https://github.com/deatil/go-cryptobin) 是一个 go 的常用加密解密库,包含了一下特性
* [go-cryptobin](https://github.com/deatil/go-cryptobin) 包括常用的对称加密和非对称加密及签名验证
* 对称加密解密(Aes/Des/TriDes/SM4/Tea/Twofish/Xts)
* 对称加密解密模式(ECB/CBC/CFB/OFB/CTR/GCM)
* 对称加密解密补码(NoPadding/ZeroPadding/PKCS5Padding/PKCS7Padding/X923Padding/ISO10126Padding/ISO97971Padding/ISO7816_4Padding/TBCPadding/PKCS1Padding)
* 非对称加密解密(RSA/SM2)
* 非对称签名验证(RSA/PSS/DSA/Ecdsa/EdDSA/SM2)
* 默认 `Aes`, `ECB`, `NoPadding`
* 项目地址: https://github.com/deatil/go-cryptobin
最新版本添加了 openssh 证书生成和解析,具体使用可以看一下示例
* ssh rsa生成使用
~~~go
package main
import (
"fmt"
"encoding/pem"
"github.com/deatil/lakego-filesystem/filesystem"
cryptobin_ssh "github.com/deatil/go-cryptobin/ssh"
cryptobin_rsa "github.com/deatil/go-cryptobin/cryptobin/rsa"
)
func main() {
fs := filesystem.New()
rsa := cryptobin_rsa.NewRsa().GenerateKey(2048)
// block, _ := cryptobin_ssh.MarshalOpenSSHPrivateKey(obj.GetPrivateKey(), "comment")
// block, _ := cryptobin_ssh.MarshalOpenSSHPrivateKeyWithPassword(obj.GetPrivateKey(), "comment", []byte("123"))
rsaBlock, _ := cryptobin_ssh.MarshalOpenSSHPrivateKeyWithPassword(
rsa.GetPrivateKey(),
"comment",
[]byte("123"),
cryptobin_ssh.Opts{
// cryptobin_ssh.AES256CBC
Cipher: cryptobin_ssh.AES256CTR,
KDFOpts: cryptobin_ssh.BcryptOpts{
SaltSize: 16,
Rounds: 16,
},
},
)
rsaBlockkeyData := pem.EncodeToMemory(rsaBlock)
fs.Put("./runtime/key/ssh/rsa-en", string(rsaBlockkeyData))
fmt.Println("生成成功")
}
~~~
有疑问加站长微信联系(非本文作者)