Giter Club home page Giter Club logo

go-cryptobin's People

Contributors

deatil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-cryptobin's Issues

[Question]: MARS2

疑惑的地方

Greetings!

First of all, I want to thank you for this fantastic library.

My question is about the origin of MARS2, is it a revision of MARS? Is there documentation about MARS2?

Thank you in advance.

[Question]: 浙里办票:电子发票数据解码

疑惑的地方

待解码内容fileResult内容为:
{"layoutFile":"uWsdr_ZxBkPL1wIMPHg8HFq-","envelope":"BM0iMjp4qiQf_3aHmtLJQHk3HIE-zokW-Ib3DAx4NvzqASUaV","fileName":"377e2d07ade20792a4542f3d71ca2e69.ofd"}

Java版本的解码函数如下:第一步从envelope中解出envelopeKey;第二步使用envelopeKey从layoutFile中解出内容

public static TrustedInvoiceContent parse2(FileResultZww fileResult, CipherParameters privateKey) {
        try {
            SM2Engine sm2Engine = new SM2Engine();
            sm2Engine.init(false, privateKey);
            byte[] encryptedKey = LiteBase64.getUrlDecoder().decode(fileResult.getEnvelope());
            byte[] envelopKey = sm2Engine.processBlock(encryptedKey, 0, encryptedKey.length);
            EncEnums encEnums = EncEnums.SM4EBC;
            Cipher cipher = Cipher.getInstance(encEnums.getDesc(), "BC");
            cipher.init(2, new SecretKeySpec(envelopKey, "SM4"));
            CompressEnums compressEnums = CompressEnums.GZIP;
            byte[] encryptedMessage = LiteBase64.getUrlDecoder().decode(fileResult.getLayoutFile());
            byte[] decodeMessage = cipher.doFinal(encryptedMessage);
            TrustedInvoiceContent trustedInvoiceContent = new TrustedInvoiceContent();
            trustedInvoiceContent.setInvoiceContent(LiteCompressUtils.gzipUncompress(decodeMessage));
            return trustedInvoiceContent;
        } catch (Exception var11) {
            throw new RuntimeException(var11);
        }
    }

其中:fileResult.envelope采用以下函数decrypt, SM2Engine.Mode.C1C2C3

private byte[] decrypt(byte[] var1, int var2, int var3) throws InvalidCipherTextException {
        byte[] var4 = new byte[this.curveLength * 2 + 1];
        System.arraycopy(var1, var2, var4, 0, var4.length);
        ECPoint var5 = this.ecParams.getCurve().decodePoint(var4);
        ECPoint var6 = var5.multiply(this.ecParams.getH());
        if (var6.isInfinity()) {
            throw new InvalidCipherTextException("[h]C1 at infinity");
        } else {
            var5 = var5.multiply(((ECPrivateKeyParameters)this.ecKey).getD()).normalize();
            int var7 = this.digest.getDigestSize();
            byte[] var8 = new byte[var3 - var4.length - var7];
            if (this.mode == SM2Engine.Mode.C1C3C2) {
                System.arraycopy(var1, var2 + var4.length + var7, var8, 0, var8.length);
            } else {
                System.arraycopy(var1, var2 + var4.length, var8, 0, var8.length);
            }

            this.kdf(this.digest, var5, var8);
            byte[] var9 = new byte[this.digest.getDigestSize()];
            this.addFieldElement(this.digest, var5.getAffineXCoord());
            this.digest.update(var8, 0, var8.length);
            this.addFieldElement(this.digest, var5.getAffineYCoord());
            this.digest.doFinal(var9, 0);
            int var10 = 0;
            int var11;
            if (this.mode == SM2Engine.Mode.C1C3C2) {
                for(var11 = 0; var11 != var9.length; ++var11) {
                    var10 |= var9[var11] ^ var1[var2 + var4.length + var11];
                }
            } else {
                for(var11 = 0; var11 != var9.length; ++var11) {
                    var10 |= var9[var11] ^ var1[var2 + var4.length + var8.length + var11];
                }
            }

            Arrays.fill(var4, (byte)0);
            Arrays.fill(var9, (byte)0);
            if (var10 != 0) {
                Arrays.fill(var8, (byte)0);
                throw new InvalidCipherTextException("invalid cipher text");
            } else {
                return var8;
            }
        }
    }

期望的结果

疑问点:如何写envelope sm2相关的调用?如何使用envelopeKey从layoutFile中解出内容?

var b_env, b_lay []byte
				b_env, e = base64.URLEncoding.DecodeString(pd.Envelope)
				b_lay, e = base64.URLEncoding.DecodeString(pd.LayoutFile)
				if e == nil {
					envKey := sm2.New().
						FromBytes(b_env).
						FromPKCS8PrivateKeyWithPassword([]byte(zlbp.PrivateKeyContent), zlbp.Password).
						SetMode("C1C3C2").
						Decrypt().
						ToString()。 ???

					result := sm2.New().
						FromBytes(b_lay).
						FromPrivateKeyString(envKey).
						Decrypt().
						ToString()。???
					fmt.Println(result)
				}

[问题]请问下招行的公钥要怎么加载呢

if publicKey == nil {
		if keyData, err := base64.StdEncoding.DecodeString(viper.GetString("keys.publicKey")); err != nil {
			return false, err
		} else {
			if publicKey, err = x509.ReadPublicKeyFromHex(hex.EncodeToString(keyData)); err != nil {
				return false, err
			}
		}
	}
	if signByte, err := base64.StdEncoding.DecodeString(signature); err != nil {
		return false, err
	} else {
		hexString := hex.EncodeToString(signByte)
		r, _ := new(big.Int).SetString(hexString[:64], 16)
		s, _ := new(big.Int).SetString(hexString[64:], 16)
		return sm2.Sm2Verify(publicKey, msg, []byte(viper.GetString("config.uid")), r, s), nil
	}

请问这种加载方式和验签方式对吗

[Question]: 浙里办票:电子发票SM4验签调用问题

疑惑的地方

email: [email protected] wechat: deepestdata

对接平台: https://dzpj.zjzwfw.gov.cn/

请问sign时,sm2的调用如何组织?目前采用以下方案,生成的signature与java版本生成的不一致,并每次都随机变动。

	block, _ := pem.Decode([]byte(privateKeyContent))
	b, e := pkcs8.DecryptPEMBlock(block, []byte(password))
	if e == nil {
		fmt.Println("DecryptPEMBlock:", bytesToHexString(b))
		//github.com/deatil/go-cryptobin/cryptobin/sm2
		result = sm2.New().
			FromString(signPayloadBody).
			FromPKCS8PrivateKeyWithPassword([]byte(privateKeyContent), password).
			Sign().
			ToHexString()
	}

java demo:

   private static String instCode = "xxxxxx";  //纳税人识别号
    //企业密码
    private static String password = "xxx";  // 企业密码
    //企业密钥
    private static String privateKeyContent = "-----BEGIN ENCRYPTED PRIVATE KEY-----\n" +
            "xxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/\n" +
            "vZxxxxxxxxxXfgDxxxxxxxxxxtjpNIOxxxxxxxxxxxxxxxxxxxxxx/\n" +
            "Nxxxxxxxxxxxxxxxx0K9LaPOsxAxxxxxxxxxxxxxxxxxxxxxKrAr3n\n" +
            "oSMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFNBDt8AX\n" +
            "sexxxxxxxxxxxxxnQiLrdwVtxxxxxxxxxxxxxxxxxx/9Uzl//6RbIt\n" +
            "Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxv==\n" +
            "----END ENCRYPTED PRIVATE KEY-----";

java签名函数:

private static String sign(String jsonStr) {
        GovDataSDK.getInstance().init(instCode, privateKeyContent, password, EncryptTpyeEnum.SM4);
        SignedRequest request = GovDataSDK.getInstance().getRequestBuilder().generateSignedPayload(jsonStr);
        return JSON.toJSONString(request);
    }

对下样例中签名选择SM3摘要,请问我们如何在调用sm2加上SM3Digest()这个动作?

//AsymmetricCipherEnum:SM2,DigestEnum:SM3

public static DsaSigner createSigner(AsymmetricCipherEnum asymmetricCipherEnum, DigestEnum digestEnum, InputStream privateKeyStream, String password) throws PKCSException, OperatorCreationException, IOException {
        X9ECParameters CURVE_PARAMS;
        switch (asymmetricCipherEnum) {
            **case SM2:
                CURVE_PARAMS = CustomNamedCurves.getByName(asymmetricCipherEnum.getCurveName());**
                switch (digestEnum) {
                    **case SM3:
                        return new Sm2Impl(CURVE_PARAMS, new SM3Digest(), privateKeyStream, password);**
//-------------
public Sm2Impl(X9ECParameters curveParameter, Digest digest, InputStream privateKeyStream, String password) throws IOException, PKCSException, OperatorCreationException {
        Security.addProvider(new BouncyCastleProvider());
        if (digest != null) {
            this.sm2Engine = new SM2Engine(digest);
        } else {
            this.sm2Engine = new SM2Engine();
        }

        this.sm2Signer = new SM2Signer();
        this.privateKeyInit = true;
        this.curve = new ECDomainParameters(curveParameter.getCurve(), curveParameter.getG(), curveParameter.getN(), curveParameter.getH());
        this.halfCurveOrder = curveParameter.getN().shiftRight(1);
        String privateKeyContent = IOUtils.toString(privateKeyStream, Charset.forName("utf-8"));
        PrivateKey privateKey = Pkcs8Utils.parseEncryptedPrivateKey(privateKeyContent, password);
        BCECPrivateKey bcecPrivateKey = (BCECPrivateKey)privateKey;
        BigInteger d = bcecPrivateKey.getD();
        ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(d, this.curve);
        this.sm2Engine.init(false, privKey);
        this.sm2Signer.init(true, privKey);
    }

期望的结果

希望能给出cryptobin相应的签名调用方法。
例如:

		result = sm2.New().
			FromString(signPayloadBody).
			FromPKCS8PrivateKeyWithPassword([]byte(privateKeyContent), password).
                        ********
			Sign().
			ToHexString()

zjsw-zlbp-demo.zip
gov-sdk-2.0.0.20220708-jar-with-dependencies.jar.zip
Uploading plate-generate-1.0.11-jar-with-dependencies.jar.zip…

[Question]: 请教招商银行生成签名后使用报错

疑惑的地方

func (s *SM4) Sm2Sign(uid, skey, data string) string {

	sm2keyBytes, _ := base64.StdEncoding.DecodeString(skey)

	return cryptobin_sm2.NewSM2().
		FromPrivateKeyBytes(sm2keyBytes).
		FromString(data).
		SignHex([]byte(uid)).
		ToBase64String()

}

以上代码,生成签名使用,招商报错 签名校验失败[Failed to
verify data using SM2 public key. case by : It’s just a failure to check, not an exception.]

期望的结果

请教

[Question]: 请教sm2如何与snowland-smx-python中sm2的加解密互通

疑惑的地方

您好,我使用 python snowland-smx-python 中无法解密[go-cryptobin] sm2密文,同样 go-cryptobin 中sm2 也无法解密snowland-smx-python生成的密文

import base64
from pysmx.SM2 import Encrypt,Decrypt
sk = base64.b64decode("qeMGjqEmmy2uQjZy87yrzbLXW/w1OLDvmjO3MlS2f3o=")
pk = base64.b64decode("hbNGUgD4vRE9fYYoyDQIB7QM47at6IEL+Pd9H6yeW12l7rMi6WrzspN5xmakfdZ4sWsTqUix0w+rgAIK2CsD3g==")
msg = "hello world"
len_para = 64
cipher_text = Encrypt(msg,pk,len_para, 0)
print("cipher_text",cipher_text)
decrypt_text = Decrypt(cipher_text,sk,len_para)
print("decrypt_text",decrypt_text)

newcipher_text ="BBtL0SS42RNWWRe1G9cHcAaKsHaflA44DTXQpSsuDap/BZiZoQ8Cc+qJRI70/utTWZlKg8HzK8HywtvRWlXK2icptvV5ABum+nqA17g9V7XRnaoepXO2BrW9Jr1q4xkpQumov9CLpLbSRA=="
decrypt_text = Decrypt(base64.b64decode(newcipher_text),sk,len_para)
print("decrypt_text",decrypt_text)

期望的结果

想请教下,应该如何互通加解密。谢谢

[Question]:

疑惑的地方

你好,我在进行招行对接时,加密结果与招行给的demo执行结果不一样,有什么建议吗?

期望的结果

可能的原因

[Bug]: PKCS5UnPadding/PKCS7UnPadding

当前版本

none

Golang 版本

1.20

是否依旧存在

可以

bug描述

当前UnPadding实现存在问题,密钥或者iv存在稍微偏差也能解密出数据或者造成out of range panic,但是为错误数据

修改建议

参考这个unpadding:

func PKCS7UnPadding(src []byte, blockSize int) ([]byte, error) {
	length := len(src)
	if blockSize <= 0 {
		return nil, errors.New("invalid blocklen")
	}

	if length%blockSize != 0 || length == 0 {
		return nil, errors.New("invalid data len")
	}

	unpadding := int(src[length-1])
	if unpadding > blockSize || unpadding == 0 {
		return nil, errors.New("invalid padding")
	}

	padding := src[length-unpadding:]
	for i := 0; i < unpadding; i++ {
		if padding[i] != byte(unpadding) {
			return nil, errors.New("invalid padding")
		}
	}

	return src[:(length - unpadding)], nil
}

[Question]: 与py不同

疑惑的地方

看到了前置4的影响,这是为啥导致的呢?

期望的结果

麻烦大佬解答下

[Bug]:

当前版本

v1.0.2021

Golang 版本

go 1.21.0

是否依旧存在

可以

bug描述

var keys = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}
ciphertext := crypto.FromString(data).SetKey("3aa61bf963dakktv").WithIv(keys).OnError(func(err []error).Aes().CBC().PKCS5Padding().Encrypt().ToBase64String()

没有错误,结果却为空,PKCS7Padding 正常

修改建议

No response

go-cryptobin 常用加密解密库新版本发布了

更新内容

新版本优化了对称加密逻辑,重构了部分代码,添加了 rsa 和 dsa 的 xml 证书格式生成和解析

项目介绍

  • go-cryptobin 包括常用的对称加密和非对称加密及签名验证
  • 项目地址 https://github.com/deatil/go-cryptobin
  • 文档地址 https://github.com/deatil/go-cryptobin/blob/main/docs/README.md
  • 对称加密解密(Aes/Des/TripleDes/SM4/Tea/Twofish/Xts)
  • 对称加密解密模式(ECB/CBC/PCBC/CFB/OFB/CTR/GCM/CCM)
  • 对称加密解密补码(NoPadding/ZeroPadding/PKCS5Padding/PKCS7Padding/X923Padding/ISO10126Padding/ISO97971Padding/ISO7816_4Padding/TBCPadding/PKCS1Padding)
  • 非对称加密解密(RSA/SM2/EIGamal)
  • 非对称签名验证(RSA/PSS/DSA/ECDSA/EdDSA/SM2/EIGamal)
  • 默认 Aes, ECB, NoPadding
  • 如果对你有帮助或者喜欢的话可以点个小星星支持下我们喔

下载安装

go get -u github.com/deatil/go-cryptobin

开始使用

package main

import (
    "fmt"

    "github.com/deatil/go-cryptobin/cryptobin/crypto"
)

func main() {
    // 加密
    cypt := crypto.
        FromString("useData").
        SetKey("dfertf12dfertf12").
        Aes().
        ECB().
        PKCS7Padding().
        Encrypt().
        ToBase64String()

    // 解密
    cyptde := crypto.
        FromBase64String("i3FhtTp5v6aPJx0wTbarwg==").
        SetKey("dfertf12dfertf12").
        Aes().
        ECB().
        PKCS7Padding().
        Decrypt().
        ToString()

    // i3FhtTp5v6aPJx0wTbarwg==
    fmt.Println("加密结果:", cypt)
    fmt.Println("解密结果:", cyptde)
}

结构说明

  • 默认方式 Aes, ECB, NoPadding
// 加密数据
cypt := crypto.
    FromString("useData").
    SetKey("dfertf12dfertf12").
    Encrypt().
    ToBase64String()
// 解密数据
cyptde := crypto.
    FromBase64String("i3FhtTp5v6aPJx0wTbarwg==").
    SetKey("dfertf12dfertf12").
    Decrypt().
    ToString()
  • 结构说明
// 使用代码
// 注意: 数据来源,设置密码,加密类型,加密模式,补码方式 在 操作类型 之前, 可以调换顺序
ret := crypto.
    FromString("string"). // 数据来源, 待加密数据/待解密数据
    SetKey("key").        // 设置密码
    SetIv("iv_string").   // 设置向量
    Aes().                // 加密类型
    CBC().                // 加密模式
    PKCS7Padding().       // 补码方式
    Encrypt().            // 操作类型, 加密或者解密
    ToBase64String()      // 返回结果数据类型

可用方法

  • 数据来源:
    FromBytes(data []byte), FromString(data string), FromBase64String(data string), FromHexString(data string)
  • 设置密码:
    SetKey(data string), WithKey(key []byte)
  • 设置向量:
    SetIv(data string), WithIv(iv []byte)
  • 加密类型:
    Aes(), Des(), TripleDes(), Twofish(), Blowfish(), Tea(rounds ...int), Xtea(), Cast5(), RC4(), Idea(), SM4(), Chacha20(nonce string, counter ...uint32), Chacha20poly1305(nonce string, additional string), Xts(cipher string, sectorNum uint64)
  • 加密模式:
    ECB(), CBC(), PCBC(), CFB(), OFB(), CTR(), GCM(nonce string, additional ...string), CCM(nonce string, additional ...string)
  • 补码方式:
    NoPadding(), ZeroPadding(), PKCS5Padding(), PKCS7Padding(), X923Padding(), ISO10126Padding(), ISO7816_4Padding(), TBCPadding(), PKCS1Padding(bt ...string)
  • 操作类型:
    Encrypt(), Decrypt(), FuncEncrypt(f func(Cryptobin) Cryptobin), FuncDecrypt(f func(Cryptobin) Cryptobin)
  • 返回数据类型:
    ToBytes(), ToString(), ToBase64String(), ToHexString()

[Bug]: 招商银行聚合支付 SM2 签名错误

当前版本

v1.0.2020

Golang 版本

go 1.20

是否依旧存在

可以

bug描述

按照 cryptobin/sm2/sm2_test.go 文件中的步骤进行加签,向招商银行聚合支付平台发送请求,返回报错信息:

{
    "returnCode": "FAIL",
    "errCode": "SIGN_ERROR",
    "sign": "...",
    "respMsg": "签名错误:RQZ7014",
    "encoding": "UTF-8",
    "version": "0.0.1",
    "signMethod": "02"
}

招商银行接口: https://api.cmburl.cn:8065/polypay/v1.0/mchorders/qrcodeapply

看过招商银行给的 java demo,里面的加签是用基于 Bouncy Castle 实现的 Sm3WithSm2 算法加签的:

public static String sm2Sign( String content,String privateKey ){
    try {
        //init privateKey
        BCECPrivateKey bcecPrivateKey = BCUtil.getPrivatekeyFromD(new BigInteger(privateKey,16));
        byte[] sign = BCUtil.signSm3WithSm2(content.getBytes(),USER_ID.getBytes(),bcecPrivateKey);
        return encodeBase64(signRawToAsn1(sign));
    }catch (Exception ex){
        ex.printStackTrace();
        return null;
    }
}

public static byte[] signSm3WithSm2(byte[] msg, byte[] userId, PrivateKey privateKey){
    return rsAsn1ToPlainByteArray(signSm3WithSm2Asn1Rs(msg, userId, privateKey));
}

public static byte[] signSm3WithSm2Asn1Rs(byte[] msg, byte[] userId, PrivateKey privateKey){
    try {
        SM2ParameterSpec parameterSpec = new SM2ParameterSpec(userId);
        Signature signer = Signature.getInstance("SM3withSM2", "BC");
        signer.setParameter(parameterSpec);
        signer.initSign(privateKey, new SecureRandom());
        signer.update(msg, 0, msg.length);
        byte[] sig = signer.sign();
        return sig;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

private static byte[] rsAsn1ToPlainByteArray(byte[] rsDer){
    ASN1Sequence seq = ASN1Sequence.getInstance(rsDer);
    byte[] r = bigIntToFixexLengthBytes(ASN1Integer.getInstance(seq.getObjectAt(0)).getValue());
    byte[] s = bigIntToFixexLengthBytes(ASN1Integer.getInstance(seq.getObjectAt(1)).getValue());
    byte[] result = new byte[RS_LEN * 2];
    System.arraycopy(r, 0, result, 0, r.length);
    System.arraycopy(s, 0, result, RS_LEN, s.length);
    return result;
}

private static byte[] bigIntToFixexLengthBytes(BigInteger rOrS){
    // for sm2p256v1, n is 00fffffffeffffffffffffffffffffffff7203df6b21c6052b53bbf40939d54123,
    // r and s are the result of mod n, so they should be less than n and have length<=32
    byte[] rs = rOrS.toByteArray();
    if(rs.length == RS_LEN) return rs;
    else if(rs.length == RS_LEN + 1 && rs[0] == 0) return Arrays.copyOfRange(rs, 1, RS_LEN + 1);
    else if(rs.length < RS_LEN) {
        byte[] result = new byte[RS_LEN];
        Arrays.fill(result, (byte)0);
        System.arraycopy(rs, 0, result, RS_LEN - rs.length, rs.length);
        return result;
    } else {
        throw new RuntimeException("err rs: " + Hex.toHexString(rs));
    }
}

修改建议

No response

[Question]: Rsa结构体多次重用的问题,解密失败。

疑惑的地方

因为我的公钥私钥是不变的,所以我想在我程序中,用一个Rsa来执行多次加解密。

但在解密时,可能出现解密失败的情况。示例代码如下:

package main

import (
	"bytes"
	crand "crypto/rand"
	"fmt"
	"math/rand"

	cryptobin "github.com/deatil/go-cryptobin/cryptobin/rsa"
)

var (
	rsaObj         cryptobin.Rsa
	priKey, pubKey []byte
)

func main() {
	obj := cryptobin.NewRsa().GenerateKey(1024)
	priKey = obj.CreatePKCS8PrivateKey().ToKeyBytes()
	pubKey = obj.CreatePKCS8PublicKey().ToKeyBytes()

	rsaObj = cryptobin.NewRsa()

	//rsaObj.FromPKCS8PublicKey(pubKey).FromPKCS8PrivateKey(priKey)
	for i := 0; i < 50; i++ {
		//rsaObj = cryptobin.NewRsa()  即使这里取消注释,每次创建一个新的Rsa,也会出现解密失败的情况
		odata := make([]byte, rand.Intn(100) + 50)
		crand.Read(odata)
		cypt := rsaObj.FromBytes(odata).FromPKCS8PublicKey(pubKey).Encrypt().ToBytes()
		data := rsaObj.FromBytes(cypt).FromPKCS8PrivateKey(priKey).Decrypt().ToBytes() // 可能成功与可能失败
		if !bytes.Equal(odata, data) {
			fmt.Println("False")
		}
	}
}

请问是使用不正确还是什么原因?

期望的结果

在公钥私钥不变的情况下,可以实现一个Rsa对象多次进行加、解密操作,而无需每次加、解密操作时都创建一个Rsa结构体。

AES/ECB/PKCS5Padding加密失败

代码:

crypto.FromBytes(src).
		SetKey("{key}").
		Aes().
		ECB().
		PKCS5Padding().
		Encrypt()

日志:

[Cryptobin: [CipherEncrypt()] the length of the completed data must be an integer multiple of the block, the completed data size is 168, block size is 16]

[Bug]: linux端使用该库打包报错

当前版本

v1.0.2019

Golang 版本

1.19.3

是否依旧存在

未测试

bug描述

Windows使用正常 但在Linux上会报错

以下为报错内容:

# github.com/deatil/go-cryptobin/cipher
../pkg/mod/github.com/deatil/[email protected]/cipher/cfb16.go:44:16: undefined: subtle.XORBytes
../pkg/mod/github.com/deatil/[email protected]/cipher/cfb32.go:44:16: undefined: subtle.XORBytes
../pkg/mod/github.com/deatil/[email protected]/cipher/cfb64.go:45:16: undefined: subtle.XORBytes
../pkg/mod/github.com/deatil/[email protected]/cipher/pcbc.go:27:26: undefined: bytes.Clone
../pkg/mod/github.com/deatil/[email protected]/cipher/pcbc.go:77:16: undefined: subtle.XORBytes
../pkg/mod/github.com/deatil/[email protected]/cipher/pcbc.go:80:16: undefined: subtle.XORBytes
../pkg/mod/github.com/deatil/[email protected]/cipher/pcbc.go:144:16: undefined: subtle.XORBytes
../pkg/mod/github.com/deatil/[email protected]/cipher/pcbc.go:146:16: undefined: subtle.XORBytes

修改建议

No response

[Bug]:

当前版本

v1.0.2071

Golang 版本

1.22.0

是否依旧存在

可以

bug描述

示例中

crypto.
FromString("useData").
SetKey("dfertf12dfertf12").
Encrypt().
ToBase64String()

	输出出来是空的

image

修改建议

No response

[Bug]:

当前版本

v1.0.2024

Golang 版本

go 1.21.0

是否依旧存在

可以

bug描述

ase 解密秘钥长度为24位时panic。
NewCipher 中是使用 key长度选择:AES-128, AES-192, or AES-256.
但是看代码里为 aes.NewCipher(aesECBGenerateKey(key)),aesECBGenerateKey强制把key设置为16位长度。不明白为何这样做?
如果为了防止秘钥位数不对,可以用截断或者补齐到16,24,32位

修改建议

No response

[Question]: cbc 256 如何设置

疑惑的地方

aes cbc 256 如何设置

期望的结果

crypto.
FromString("xxxxx").
SetKey("xxxx").
SetIv("xxx").Aes().
**CBC256().**
PKCS7Padding().
Encrypt().
ToBase64String()

[Bug]: undefined: subtle.XORBytes

当前版本

v1.0.2037

Golang 版本

go 1.9

是否依旧存在

可以

bug描述

Hi,
when i use this package there have some error:

../../../go/pkg/mod/github.com/deatil/[email protected]/cipher/cfb16.go:44:16: undefined: subtle.XORBytes
../../../go/pkg/mod/github.com/deatil/[email protected]/cipher/cfb32.go:44:16: undefined: subtle.XORBytes
../../../go/pkg/mod/github.com/deatil/[email protected]/cipher/cfb64.go:45:16: undefined: subtle.XORBytes
../../../go/pkg/mod/github.com/deatil/[email protected]/cipher/ncfb.go:54:16: undefined: subtle.XORBytes
../../../go/pkg/mod/github.com/deatil/[email protected]/cipher/nofb.go:94:16: undefined: subtle.XORBytes
../../../go/pkg/mod/github.com/deatil/[email protected]/cipher/pcbc.go:27:26: undefined: bytes.Clone
../../../go/pkg/mod/github.com/deatil/[email protected]/cipher/pcbc.go:77:16: undefined: subtle.XORBytes
../../../go/pkg/mod/github.com/deatil/[email protected]/cipher/pcbc.go:80:16: undefined: subtle.XORBytes
../../../go/pkg/mod/github.com/deatil/[email protected]/cipher/pcbc.go:144:16: undefined: subtle.XORBytes
../../../go/pkg/mod/github.com/deatil/[email protected]/cipher/pcbc.go:146:16: undefined: subtle.XORBytes
../../../go/pkg/mod/github.com/deatil/[email protected]/cipher/pcbc.go:146:16: too many errors
note: module requires Go 1.20

is it dont support go 1.7 or 1.9 ?
thank you ,
谢谢。

修改建议

No response

gost 证书示例

-----BEGIN PRIVATE KEY-----
MEYCAQAwHwYIKoUDBwEBAQEwEwYHKoUDAgIjAQYIKoUDBwEBAgIEIJ3L20nIrfUo
MdMNKTx9pxh3e7Etf7abOI73mypFZToK
-----END PRIVATE KEY-----

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.