-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
兼容性问题 #189
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使用该库对字符串"C06FFCB5FDD40F45B444CDB4E1109DD9F404F85E57ECD0A0E4CF53FE400153E4"进行SM4解密。
解密密钥"NEWCAPECNEWCAPEC"
解密成功,代码如下:
package main
import (
"crypto/cipher"
"encoding/hex"
"fmt"
)
func sm4Dectypt(cipherText, key []byte) []byte {
block, err := sm4.NewCipher(key)
if err != nil {
panic(err)
}
iv := []byte("-----------------------------------") //填入你的IV string
blockMode := cipher.NewCBCDecrypter(block, iv)
blockMode.CryptBlocks(cipherText, cipherText)
// plainText := unpaddingLastGroup(cipherText)
return cipherText
}
func main() {
key := []byte("-------------------") //key string
data1, _ := hex.DecodeString("C06FFCB5FDD40F45B444CDB4E1109DD9F404F85E57ECD0A0E4CF53FE400153E4") //输入你想要的解密内容 string
plainText := sm4Dectypt(data1, key) //解密
fmt.Printf("解密结果 = %s\n", plainText)
}
但该密文不能用目前流行的C#库(BouncyCastle、Sw.ChinaEncryptSM、Vive.Crypto)解密。
//https://gitee.com/stoneson/Vive.Crypto
//Vive.Crypto
//无法解密
//var crypto = CryptoFactory.CreateSymmetric(SymmetricProviderType.SM4);
//var text1 = crypto.Decrypt(cipherText, key);
如果对同样的密文,使用同样的密钥加密,使用这些库进行加密后的密文与此库可解密的密文不一致。
The text was updated successfully, but these errors were encountered: