workshop

package module
v0.0.0-...-57c3e09 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

国密workshop

这个demo旨在启动一个国密的服务器(公钥)并且通过命令行来执行对应的操作从而体验非对称加密过程中的签名,验证,加密,解密过程。

项目结构

  • client 客户端代码
  • server 服务器代码
  • 其他

步骤

  1. 编译项目
terminal 1

cd server && go build .

terminal 2

cd client && go build .

  1. 生成密钥并配置
terminal 2

./client ./ generate mv pub.pem ../server

  1. 启动服务器
terminal 1

./server ./

  1. 通过命令行发送请求
terminal 2

./client ./ sign 127.0.0.1:8080 ./client ./ decrypt 127.0.0.1:8080 ./client ./ sm4 127.0.0.1:8080

设计

  • server/client restapi接口
  • 通用load key,sign,verify接口
  • 底层基础库实现(支撑)

相关资源

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CCS = "CCS"
View Source
var PKU = "PKU"
View Source
var TJ = "TJ"

Functions

func DegistAndSign

func DegistAndSign(msg []byte, priv SM2) ([]byte, error)

func DegistAndVerify

func DegistAndVerify(msg, sign []byte, pub SM2) bool

func ReadFile

func ReadFile(filename string) ([]byte, error)

todo lib

func WriteFile

func WriteFile(content []byte, filename string) error

Types

type CCSSM2

type CCSSM2 struct {
	PrivateKey *ccs.PrivateKey
	PublicKey  *ccs.PublicKey
}

func CCSImportKey

func CCSImportKey(privPEM []byte, pubPEM []byte) (*CCSSM2, error)

func NewCCSSM2

func NewCCSSM2() (*CCSSM2, error)

func (*CCSSM2) Decrypt

func (instance *CCSSM2) Decrypt(encrypted []byte) ([]byte, error)

func (*CCSSM2) Encrypt

func (instance *CCSSM2) Encrypt(msg []byte) ([]byte, error)

func (*CCSSM2) ExportKey

func (instance *CCSSM2) ExportKey() (privPEM []byte, pubPEM []byte, err error)

func (*CCSSM2) SaveFile

func (instance *CCSSM2) SaveFile(priFile, pubFile string) error

TODO

func (*CCSSM2) Sign

func (instance *CCSSM2) Sign(msg []byte) ([]byte, error)

func (*CCSSM2) Verify

func (instance *CCSSM2) Verify(msg []byte, sign []byte) bool

type CCSSM4

type CCSSM4 struct {
	Key []byte
}

func NewCCSSM4

func NewCCSSM4() (*CCSSM4, error)

func (*CCSSM4) Decrypt

func (instance *CCSSM4) Decrypt(encrypted []byte, mode string) ([]byte, error)

func (*CCSSM4) Encrypt

func (instance *CCSSM4) Encrypt(msg []byte, mode string) ([]byte, error)

type SM2

type SM2 interface {
	Encrypt(msg []byte) ([]byte, error)
	Decrypt(encrypted []byte) ([]byte, error)
	Sign(msg []byte) ([]byte, error)
	Verify(msg []byte, sign []byte) bool
	ExportKey() (privPEM []byte, pubPEM []byte, err error)
	SaveFile(priFile, pubFile string) error
}

func GenerateSM2Instance

func GenerateSM2Instance(sourceDef string) (SM2, error)

func LoadFromPriPem

func LoadFromPriPem(file string) (SM2, error)

todo lib

func LoadFromPubPem

func LoadFromPubPem(file string) (SM2, error)

type SM4

type SM4 interface {
	Encrypt(msg []byte, mode string) ([]byte, error)
	Decrypt(encrypted []byte, mode string) ([]byte, error)
}

func GenerateSM4Instance

func GenerateSM4Instance(sourceDef string) (SM4, error)

type TJSM2

type TJSM2 struct {
	PrivateKey *tj.PrivateKey
	PublicKey  *tj.PublicKey
}

func NewTJSM2

func NewTJSM2() (*TJSM2, error)

func TJImportKey

func TJImportKey(privPEM []byte, pubPEM []byte) (*TJSM2, error)

func (*TJSM2) Decrypt

func (instance *TJSM2) Decrypt(encrypted []byte) ([]byte, error)

func (*TJSM2) Encrypt

func (instance *TJSM2) Encrypt(msg []byte) ([]byte, error)

func (*TJSM2) ExportKey

func (instance *TJSM2) ExportKey() (privPEM []byte, pubPEM []byte, err error)

func (*TJSM2) SaveFile

func (instance *TJSM2) SaveFile(priFile, pubFile string) error

func (*TJSM2) Sign

func (instance *TJSM2) Sign(msg []byte) ([]byte, error)

func (*TJSM2) Verify

func (instance *TJSM2) Verify(msg []byte, sign []byte) bool

type TJSM4

type TJSM4 struct {
	Key []byte
}

func NewTJSM4

func NewTJSM4() (*TJSM4, error)

func (*TJSM4) Decrypt

func (instance *TJSM4) Decrypt(encrypted []byte, mode string) ([]byte, error)

func (*TJSM4) Encrypt

func (instance *TJSM4) Encrypt(msg []byte, mode string) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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