1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 23:22:28 +08:00

feat: add GenerateRsaKeyPair, RsaEncryptOAEP, RsaDecryptOAEP

This commit is contained in:
dudaodong
2023-09-14 14:06:54 +08:00
parent f445ecbaf8
commit 8ff37f0eff
3 changed files with 73 additions and 1 deletions

View File

@@ -1,6 +1,8 @@
package cryptor
import "fmt"
import (
"fmt"
)
func ExampleAesEcbEncrypt() {
data := "hello"
@@ -484,3 +486,25 @@ func ExampleSha512WithBase64() {
// Output:
// m3HSJL1i83hdltRq0+o9czGb+8KJDKra4t/3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==
}
func ExampleRsaEncryptOAEP() {
pri, pub := GenerateRsaKeyPair(1024)
data := []byte("hello world")
label := []byte("123456")
encrypted, err := RsaEncryptOAEP(data, label, *pub)
if err != nil {
return
}
decrypted, err := RsaDecryptOAEP([]byte(encrypted), label, *pri)
if err != nil {
return
}
fmt.Println(string(decrypted))
// Output:
// hello world
}