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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Golang Rsa 加密 解密

2019-11-11 03:04:30
字體:
供稿:網(wǎng)友

1)創(chuàng)建私鑰:

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

2)創(chuàng)建公鑰:

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)}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 江口县| 万载县| 紫阳县| 长海县| 黑水县| 来凤县| 略阳县| 九台市| 南京市| 庐江县| 唐海县| 修文县| 巢湖市| 陕西省| 正宁县| 邳州市| 通江县| 浑源县| 邛崃市| 大同县| 宝丰县| 河池市| 宜良县| 青海省| 隆子县| 阿图什市| 明水县| 秭归县| 晋江市| 昆山市| 霍城县| 孝感市| 武强县| 巴林左旗| 鄯善县| 扎兰屯市| 辽宁省| 巩义市| 扬州市| 文成县| 鱼台县|