2024-07-16 16:51:39 +08:00
|
|
|
package rsa
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"github.com/bytedance/sonic"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
const prik = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCmjK6SPkrP03ssex5Dxn4KZeVm9rQoJMslru13GNgoGKJAq13xwUGl6lpGlhzM9IMzg0ldOO2a0SQPPjc0fLrDjIgHPfIT6H1hDGkZdPaF4D0OfiHGzlLwXq7FyyyGc2JXILsniMBXcCxNFhbW0jAaJyYrBJb3q84a5y5AtK3IC+eDV6Bj2J4HlQVGKgW9u2ic6Jxl23sacXY6iifi+KEuoXNCJrmYlgRWTaQovLmTCLkErkzxzG9DFRDWGoz25LthDPqcCSUmWEbJ+obwIGB4r2WCbFXvaeVBQORlyVRyNUvYMItjHBQIKinDWZ6y8KzA0YKOoxEfr0KfE8Uk4PQBAgMBAAECggEABTAX0PzelN4uyvTT0sMi/R0YRKPgepP40vtBsNvF10E7Lp4ClAupHpYFSrJq178xu1/2dVBXEGM9hw8GUQd7RCjuD3cFwcp/EKU+Zy6uQ38iZRTskEDa3bC+q3EXzuFXDxqOfIhai262UTlkATw0sjUwJRdkbMxoeWHkSNuH7UBVddxFL8Bq1DKaPzRCqQ8zlkMZHy8Xbf2b8rFoi1oPBoPjHyxCo33zcnSg5xntIoA5pkD6x4z5cAnU55aBoYUiRv7jmG+MVp1jpDvAmJLfUayVZNakgX1r74bMPsl9kpA7dVdgOlWrIkbJE1plVXXswBb8QKN0/Yx2vv/YASSi0QKBgQDaO9BkRjvht/lrsQEur1wXf5ITnsVWsqlUhYQKGHihzOj7e0rGO9QICM4eQZH9ssHfxEXhmEoFdkaqo3Fo47NI+yinpWm+KruwrRFkCGejlKZ4bhn9zWPb8L1qJbN4UD1c5jUNk1B0EEdnLRFg0/O7xm602bG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VL2DCLYxwUCCopw1mesvCswNGCjqMRH69CnxPFJOD0AQIDAQAB"
|
|
|
|
|
|
|
|
func Test_en(t *testing.T) {
|
2024-11-04 14:05:53 +08:00
|
|
|
data := "{\"createTime\":1727597377,\"deliverOrderNo\":\"DELIVER_test\",\"extendParams\":\"{\\\"appId\\\":\\\"YL20220531\\\",\\\"num\\\":1,\\\"posId\\\":\\\"YL20220531\\\"}\",\"requestTime\":1727597377,\"supplierId\":10702124,\"supplierSkuId\":632,\"thirdSkuId\":\"20240806YLYK\"}"
|
2024-07-16 16:51:39 +08:00
|
|
|
dataJson, _ := json.Marshal(data)
|
|
|
|
pub := `-----BEGIN PUBLIC KEY-----
|
|
|
|
` + pubk + `
|
|
|
|
-----END PUBLIC KEY-----`
|
|
|
|
res, err := Encrypt(pub, dataJson)
|
|
|
|
fmt.Println(base64.StdEncoding.EncodeToString(res), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_de(t *testing.T) {
|
|
|
|
data := "oSpZJFBORDtJDpKjk5q4C1ex7CbgDW+YjMS7gCQHIsn1dgrSXEvjgeuA2jhc29CstkIDjwQ/qhInXVl/M9hphB9oujfegD+FPRspRhDrBY1csuPLDiKZh82LQfPMMXCQcZk73F+OfHl9cX/QLi/2uRUw3UsEO8Hv6o9VM1mSkg+uWAqqFKZKvVXJBTNHRzlQ56LTMZG8kwGGQisoCvi+f+6B/3Kd9co+csMAEeE+gK/Ix+c8jLs5lL8QKZW9vALa8zgTPG3oicxIYHqNoPqc8Z/R+C69k30QRsbWhyixPpSGxGkV9Pvy8czj/t+uoDiZ7hOQugR9ss7DIwZHuyDcHA=="
|
|
|
|
privateKeyPEM := `-----BEGIN RSA PRIVATE KEY-----
|
|
|
|
` + prik + `
|
|
|
|
-----END RSA PRIVATE KEY-----`
|
|
|
|
res, err := Decrypt(privateKeyPEM, data)
|
|
|
|
fmt.Println(string(res), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_sonic(t *testing.T) {
|
|
|
|
var a map[string]interface{}
|
|
|
|
b := "{\"severType\":\"sms\",\"msgType\":\"sms\",\"base\":{\"serverIndex\":\"sms\",\"tempIndex\":\"sms\"},\"config\":\"{\\\"param\\\":\\\"{\\\\\\\"plan_id\\\\\\\":\\\\\\\"1234\\\\\\\",\\\\\\\"key_batch_id\\\\\\\":\\\\\\\"1234\\\\\\\",\\\\\\\"stock\\\\\\\":\\\\\\\"1234\\\\\\\",\\\\\\\"warning_num\\\\\\\":\\\\\\\"1234\\\\\\\",\\\\\\\"per\\\\\\\":\\\\\\\"1234\\\\\\\"}\\\",\\\"tels\\\":\\\"15082245107\\\"}\"}"
|
|
|
|
sonic.Unmarshal([]byte(b), &a)
|
|
|
|
fmt.Println(a)
|
|
|
|
}
|