| 136 | } |
| 137 | |
| 138 | func rsaDecrypt(ciphertext []byte, privateKey string) ([]byte, error) { |
| 139 | block, _ := pem.Decode([]byte(privateKey)) |
| 140 | if block == nil { |
| 141 | return nil, fmt.Errorf("private key error!") |
| 142 | } |
| 143 | priv, err := x509.ParsePKCS1PrivateKey(block.Bytes) |
| 144 | if err != nil { |
| 145 | return nil, fmt.Errorf(fmt.Sprintf("Parse private key error:%s", err)) |
| 146 | } |
| 147 | return rsa.DecryptPKCS1v15(rand.Reader, priv, ciphertext) |
| 148 | } |
| 149 | |
| 150 | func DecryptPasswordSupportNoRsaKey(password string, rsaPrivateKey string) (realPwd string, err error) { |
| 151 | if "" == rsaPrivateKey { |