We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
使用该库对字符串"C06FFCB5FDD40F45B444CDB4E1109DD9F404F85E57ECD0A0E4CF53FE400153E4"进行SM4解密。 解密密钥"NEWCAPECNEWCAPEC"
解密成功,代码如下: package main
import ( "crypto/cipher" "encoding/hex" "fmt"
"github.com/tjfoc/gmsm/sm4"
)
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);
//Sw.ChinaEncryptSM //无法解密 SM4Utils sM4Utils = new SM4Utils(); sM4Utils.secretKey = key; var text2 = sM4Utils.Decrypt_CBC_Hex(cipherText);
如果对同样的密文,使用同样的密钥加密,使用这些库进行加密后的密文与此库可解密的密文不一致。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
使用该库对字符串"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: