kefu/tools/rsa2_test.go

64 lines
2.5 KiB
Go
Raw Normal View History

2024-12-10 02:50:12 +00:00
package tools
import (
"crypto"
"log"
"testing"
)
const (
// 私钥
PRIVATE_KEY = `
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAvSa9KsScy+ZuFTiPLE7ZwMacmxmA6A8fu0jiPluliLwutgRO
TTZp3g9HmW1CuYt+ZoQH9t0JzHHNFu9yCetJdt5TrpQx9bBovTsh8h/ZQOPsyo0p
nKqi5G3x1Azvbzs6yTU8voz6xVT90/DVJcd71osTsn+7ajEZccfa35tl5DBdF95t
hWeyMz5p6ayFMUEU10HBUYmYTUzi4dvXcZUZvLOIOPMHoCTXcX98EmGqUvsLWpx8
mscaA5llZMg+ZXnT5OH+HW9ncfz7DqXiON3yo1BrNPdmN+Y4SI9dWrADUzGJO6u5
8OwncCphUsYqnlG2jd4n0JhjpA2WGD4c6zqJJQIDAQABAoIBAAOmqMYXj3M8Gmnc
cp8HUpqu+rzfrCZOjG1ABeXwPOy7vScURDKnVznLD7W9bylHsQPnjoPMVnEUzUGh
E5FvcjaSKglXoPM+GXd1mb0jsjzXaW2rdd8pSAWivaU7Lq/187eIiIihDgIbFt8t
ad/VzuUgQBwU7RgqpHQWyHnCdSAHanV6TDDzRssJPdVBVLHOgmiMthSw8OtJiXy7
p8oKVsMiLk/+nNKXBorpx4EhYdB4u+XreMBChLT/AYQfZ6Q9xvAVoRnSaFplvqNw
Xlxwo0T5tMZLla4QafZ+fQM9GvDudv2NebHvDbL6zTefthCYDK8utaQpcnm70WBp
NFdOuW0CgYEA4EAmFxhdop7T+iLcG4LMXAGhvyEmArtQftsfUKcuYV/vXbsX0pj/
64WmriVfFhyW+d27ZrDZ0knT9in6zfxER3mAigVvd5SJ2co10HiiIRNfMZKXjc3g
pKukPAw0fsrBhp1Cdml649RZnTdl7FaUs6xmWIszQi2fUca8HlF3wBMCgYEA1+5v
WTV+rcVh9qhs2y8feuWWkmYDVZMbmgE+V+bo4o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GJO6u58OwncCphUsYqnlG2jd4n0JhjpA2WGD4c6zqJ
JQIDAQAB
-----END PUBLIC KEY-----
`
)
func TestRsa2Rsa2PriSign(t *testing.T) {
//原内容
str := "F78691A5-2963-42D2-A0C7-3A4F31CF5EB6"
//生成签名
sig := Rsa2PriSign(str, PRIVATE_KEY, crypto.SHA256)
log.Println(sig)
//验证原内容与签名是否一致
res, _ := Rsa2PubCheckSign(str, sig, PUBLIC_KEY, crypto.SHA256)
log.Println(res)
}