|
@@ -96,15 +96,16 @@ func DisplacementEncryption(content string) (string, error) {
|
|
|
if content == "" {
|
|
|
return "", errors.New("加密内容为空")
|
|
|
}
|
|
|
- plaintext := []byte(content)
|
|
|
- if Displacement != 0 { // 位移处理的值
|
|
|
- shiftValue := big.NewInt(Displacement)
|
|
|
- PublicKey.E = int(shiftValue.Int64())
|
|
|
+ if PrivateKey == nil {
|
|
|
+ return "", errors.New("无效私钥")
|
|
|
}
|
|
|
- // 使用公钥加密数据
|
|
|
- ciphertext, err := rsa.EncryptPKCS1v15(rand.Reader, PublicKey, plaintext)
|
|
|
+
|
|
|
+ plaintext := []byte(content)
|
|
|
+ shiftValue := big.NewInt(Displacement)
|
|
|
+ PrivateKey.D = new(big.Int).Mul(PrivateKey.D, shiftValue)
|
|
|
+ ciphertext, err := rsa.EncryptPKCS1v15(rand.Reader, &PrivateKey.PublicKey, plaintext)
|
|
|
if err != nil {
|
|
|
- log.Println("加密失败:", err)
|
|
|
+ fmt.Println("加密失败:", err)
|
|
|
return "", err
|
|
|
}
|
|
|
return string(ciphertext), nil
|
|
@@ -118,10 +119,8 @@ func DisplacementDecryption(content string) (string, error) {
|
|
|
if PrivateKey == nil {
|
|
|
return "", errors.New("无效私钥")
|
|
|
}
|
|
|
- if Displacement != 0 {
|
|
|
- exponent := big.NewInt(Displacement) // 位移处理的值
|
|
|
- PrivateKey.D = new(big.Int).Mul(PrivateKey.D, exponent)
|
|
|
- }
|
|
|
+ exponent := big.NewInt(Displacement) // 位移处理的值
|
|
|
+ PrivateKey.D = new(big.Int).Mul(PrivateKey.D, exponent)
|
|
|
ciphertext, err := base64.StdEncoding.DecodeString(content)
|
|
|
if err != nil {
|
|
|
log.Println("密文解码失败:", err)
|