国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Golang Rsa 加密 解密

2019-11-11 03:04:44
字體:
來源:轉載
供稿:網友

1)創建私鑰:

openssl genrsa -out PRivate.pem 1024 //密鑰長度,1024覺得不夠安全的話可以用2048,但是代價也相應增大

2)創建公鑰:

openssl rsa -in private.pem -pubout -out public.pem

publicKey <--- public.pemprivateKey <--- private.pem

// 加密func RsaEncrypt(origData []byte) ([]byte, error) {	block, _ := pem.Decode(publicKey)	if block == nil {		return nil, errors.New("public key error")	}	pubInterface, err := x509.ParsePKIXPublicKey(block.Bytes)	if err != nil {		return nil, err	}	pub := pubInterface.(*rsa.PublicKey)	return rsa.EncryptPKCS1v15(rand.Reader, pub, origData)}
// 解密func RsaDecrypt(ciphertext []byte) ([]byte, error) {	block, _ := pem.Decode(privateKey)	if block == nil {		return nil, errors.New("private key error!")	}	priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)	if err != nil {		return nil, err	}	return rsa.DecryptPKCS1v15(rand.Reader, priv, ciphertext)}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 葵青区| 石泉县| 荆州市| 万州区| 晋宁县| 博兴县| 怀柔区| 庆元县| 建平县| 茂名市| 舞阳县| 保山市| 东光县| 泗洪县| 丰都县| 齐齐哈尔市| 天全县| 九龙县| 新乡县| 襄樊市| 山东省| 尚志市| 昌黎县| 邯郸市| 南康市| 温泉县| 罗平县| 开原市| 林州市| 怀化市| 马关县| 东丽区| 周至县| 五原县| 富阳市| 文山县| 汪清县| 嵊州市| 靖远县| 蒙阴县| 永胜县|