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

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

Golang Rsa 加密 解密

2019-11-11 03:21:59
字體:
來源:轉載
供稿:網友

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


上一篇:自定義注解

下一篇:OnDraw與OnPaint對比

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汨罗市| 北票市| 平阴县| 甘孜县| 汉源县| 奉新县| 报价| 潍坊市| 铜梁县| 保定市| 开远市| 郁南县| 襄汾县| 崇礼县| 尼木县| 大安市| 新巴尔虎左旗| 天气| 池州市| 天峻县| 广宁县| 出国| 金沙县| 五寨县| 江阴市| 宜阳县| 旬阳县| 集贤县| 郴州市| 伊川县| 横峰县| 时尚| 桂平市| 宁陕县| 东光县| 北票市| 阜新市| 巴彦淖尔市| 沛县| 沙雅县| 绵竹市|