8 Star 33 Fork 14

Cliven/gotlcp

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
main.go 2.88 KB
Copy Edit Raw Blame History
package main
import (
"crypto"
"gitee.com/Trisia/gotlcp/tlcp"
"github.com/emmansun/gmsm/smx509"
"io"
)
func main() {
/*
构造签名密钥对
*/
sigCert, err := smx509.ParseCertificatePEM([]byte(SIG_CERT_PEM))
if err != nil {
panic(err)
}
sigCertKeypair := tlcp.Certificate{
Certificate: [][]byte{sigCert.Raw},
PrivateKey: &CustomSigKeypair{},
}
/*
构造加密密钥对
*/
encCert, err := smx509.ParseCertificatePEM([]byte(ENC_CERT_PEM))
if err != nil {
panic(err)
}
encCertKeypair := tlcp.Certificate{
Certificate: [][]byte{encCert.Raw},
PrivateKey: &CustomEncKeypair{},
}
_ = sigCertKeypair
_ = encCertKeypair
}
// CustomSigKeypair 自定义签名密钥对
type CustomSigKeypair struct{}
func (m *CustomSigKeypair) Public() crypto.PublicKey {
panic("请实现返回公钥")
}
func (m *CustomSigKeypair) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) (signature []byte, err error) {
panic("请实现完成数字签名")
}
// CustomEncKeypair 自定义加密密钥对
type CustomEncKeypair struct{}
func (c *CustomEncKeypair) Public() crypto.PublicKey {
panic("请实现返回公钥")
}
func (c *CustomEncKeypair) Decrypt(rand io.Reader, msg []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error) {
panic("请实现完成数据解密")
}
const (
SIG_CERT_PEM = `-----BEGIN CERTIFICATE-----
MIICHTCCAcSgAwIBAgIIAs5iVWOA17swCgYIKoEcz1UBg3UwQjELMAkGA1UEBhMC
Q04xDzANBgNVBAgMBua1meaxnzEPMA0GA1UEBwwG5p2t5beeMREwDwYDVQQKDAjm
tYvor5VDQTAeFw0yMjA3MTUxMzU5MzhaFw0yMzA3MTUxMzU5MzhaMF4xCzAJBgNV
BAYTAmNuMQ8wDQYDVQQIDAbmtZnmsZ8xDzANBgNVBA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4EFgQU9SD+JHfBKpsN/+zbSSkZnw1qVdAwHwYDVR0jBBgwFoAUNpPjFOdFCfrV
7+ovEi3ToZY8wqQwDwYDVR0RBAgwBocEfwAAATAKBggqgRzPVQGDdQNIADBFAiAD
29ovbTAIhZgfvAYKXphZSvcMnQ3QdCDyCqb4j8KMQwIhAINoMaInvyMB86C/aa7P
gqBZDVjZd/X+yWxzRGtLG/AT
-----END CERTIFICATE-----
`
)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/Trisia/gotlcp.git
git@gitee.com:Trisia/gotlcp.git
Trisia
gotlcp
gotlcp
v1.3.5

Search

0d507c66 1850385 C8b1a773 1850385