https://github.com/asppj/rsa
rsa非对称加密解密,分段加密解密
https://github.com/asppj/rsa
Last synced: 4 months ago
JSON representation
rsa非对称加密解密,分段加密解密
- Host: GitHub
- URL: https://github.com/asppj/rsa
- Owner: asppj
- License: mit
- Created: 2020-05-11T01:32:41.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-11T01:37:41.000Z (about 5 years ago)
- Last Synced: 2024-06-20T14:29:55.724Z (about 1 year ago)
- Language: Go
- Size: 3.91 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rsa
rsa非对称加密解密,分段加密解密```go
package rsaimport (
"testing"
)const tLongStr = "333333333333333333333333333333333333333333333333333####################################################################################33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"
func TestRsa(t *testing.T) {
// 生成密钥对,保存到文件
pub, pvt, err := GenerateRSAKeyPairs()
if err != nil {
t.Error(err)
}
tStr := "hello world你好,rsa"
message := []byte(tStr)
// 加密
cipherText, err := Encrypt(message, pub)
if err != nil {
t.Error(err)
}
if tStr == string(cipherText) {
t.Error("加密失败")
}
// 解密
plainText, err := Decrypt(cipherText, pvt)
if err != nil {
t.Error(err)
}
if string(plainText) != tStr {
t.Error("加解密失败")
}
longMsg := []byte(tLongStr)
cipherTextLong, err := EncryptPadding(longMsg, pub)
if err != nil {
t.Error(err)
return
}
if tLongStr == string(cipherTextLong) {
t.Error("加密失败")
return
}
// 解密
plainTextLong, err := DecryptPadding(cipherTextLong, pvt)
if err != nil {
t.Error(err)
return
}
if string(plainTextLong) != tLongStr {
t.Error("加解密失败")
return
}
}```