Skip to content

更新日志 ​

v1.3.0 (2026-10-19) ​

✨ 新功能 ​

  • 新增 SM2 的 ASN.1 密文与签名格式:Sm2CipherMode 新增 ASN1C1C2C3 和 ASN1C1C3C2,密文可以是 DER 编码的 SEQUENCE { x INTEGER, y INTEGER, C2 OCTET STRING, C3 OCTET STRING },即 BouncyCastle、Java 与多数国密网关的输出格式,不再局限于 C1 || C2 || C3、C1 || C3 || C2 的裸字节排列;新增 Sm2SingMode(默认 ASN1,可选 Bytes)与 SetSingMode,签名既可以是 DER 的 SEQUENCE { r, s },也可以是固定 64 字节的 r || s;两种格式均使用 cryptobyte 解析,数据被截断或不是合法 DER 时直接返回错误,而不是被悄悄误读;NewSm2KeyPair 保持 ASN1 为默认值(by @Web-Coke in #40)
  • 将摩斯电码字母表补齐到 ITU-R M.1677-1 全表及国际扩展字符:新增 ¡、¿、å/Å、ä/Ä、é/É、ñ/Ñ、ó/Ó、ö/Ö、ú/Ú,编码取自 codigomorse.org,并标注每组字符对应的 ITU 条款来源,同时把 / 归入标点分组;注意有两个已有映射发生变化:< 由 .--.- 改为 .--.--(.--.- 现已分配给 å),\n 改为 .-..-..,不再与 \r 共用同一编码;用 v1.2.3 编码的这两类字符,解码结果会随之变化(by @htlsmilework in #42)

🐛 修复 ​

  • 修复 ascii85 解码在存在 z 缩写时截断输出的问题:encoding/ascii85 会把全零的四字节分组编码成单个 z,本库的编码器同样如此,但解码器按严格的 5:4 比例用字符数重算目标长度,并把标准库给出的正确结果截断到该长度,导致五个零字节往返后只剩两个、八个零字节只剩一个,且不报任何错误;现在 z 不再计入该比例而按四字节计算,目标缓冲区也按缩写所隐含的展开量分配(by @youdie006 in #44)
  • 修复 ascii85 解码在四个及以上零分组时失败的问题:上述长度修复之后,u 补齐仍使用 len(src)%5,存在 z 缩写时最后一组可能只剩一个字符,而 encoding/ascii85 会拒绝这种输入——十六个零字节(编码为 zzzz)因此完全无法解码;现在两个解码器都按非 z 的长度补齐(by @youdie006 in #47)
  • 修复 base58、base62 流式编解码结果与批量接口不一致的问题:两种编码都把输入视为一个大整数,无法拆成互相独立的块,但流式编码器每 8 字节编一次、流式解码器每 1024 字节解一次,导致 Encode.FromFile(...).ByBase58()、ByBase62() 与同样数据的 FromBytes() 结果不同,且该结果无法解码回原文;现在流式编码器按文档承诺缓存输入并在 Close 时一次性编码,解码器读取全部输入后一次性解码,并在消费过程中释放缓冲区(by @Shaisolaris in #48)
  • 修复密钥对拒绝其他工具生成的密钥、并在算法不匹配时 panic 的问题:此前只有当密钥与 GenKeyPair 的输出逐字节一致(即 PUBLIC KEY/PRIVATE KEY PEM 块中承载 PKIX 或 PKCS#8 DER)时才会被接受;多数 SM2、Ed25519 生成器输出的 base64 或原始密钥材料会失败于 invalid public key: <nil> 或难以理解的 ASN.1 错误,把 RSA 密钥传给 Ed25519 密钥对则会因类型断言结果未检查而 panic(#41);现在所有 Parse*、Format*、Set* 方法统一经过一个选择器,依次尝试 PEM、base64(四种字母表、可带或不带填充)、十六进制与原始密钥材料,由各算法自己的解析器决定哪种解释成立——Ed25519 接受 PKIX/PKCS#8 DER、32 字节种子和 64 字节私钥,SM2 接受 PKIX/PKCS#8 DER、65 字节非压缩点与 32 字节标量,RSA 接受 PKIX/PKCS#1 DER;SM2 的密钥格式化改用本地 SPKI/PKCS#8 编码器(crypto/x509 不支持 SM2),输出仍可被 OpenSSL、Java 解析;Set*Key 接受 PEM 并归一化输出,算法或方向不符的 PEM 块在解析前即以 UnsupportedKeyFormatError 拒绝(提示 the parsed key is an RSA key, not an Ed25519 key),错误信息不再打印 <nil>,Compress*Key 改用 pem.Decode 而不再做字符串裁剪,因此可处理可选的块头,SM2 私钥标量也会校验落在 [1, n-1] 区间——此前 d = 0 会产生没有公钥点的密钥(by @gouguolei in 012269d)

⚡ 性能优化 ​

  • 摩斯解码只构建一次反向字母表,不再逐字符扫描:StdDecoder.Decode 为每个符号遍历整张 StdAlphabet 直到命中,使解码成为 O(n × 89) 而非 O(n),CPU 采样中有 53% 的时间耗在 map 遍历上;现在按 base45、base91 已有的做法在 init() 中一次性构建反查表,几何平均耗时下降 89.21%(4096 字符:1222µs → 103µs),内存分配次数不变;这次扫描还让解码结果不确定——有七个编码由大小写成对共享(.--.- 同时属于 Å 和 å,ä、é、ñ、ó、ö、ú 同理),而 map 遍历顺序随机,导致 .--.- 有 62% 的概率解成 Å,这些字符的编码再解码并不无损;反查表把这类冲突统一解析为小写形式,这也是 Encode 唯一能产生的结果(by @darakanoit in #46)

🔧 重构 ​

  • 将密钥序列化统一收敛到包级函数变量:marshalPKIXPublicKey、marshalPKCS8PrivateKey 现在是包装 crypto/x509 的变量,marshalSm2PublicKey、marshalSm2PrivateKey 包装本地的 SM2 编码器,从而可以在测试中模拟 Format*Key 的错误分支——对于已经解析成具体类型的密钥,crypto/x509 永远不会失败;RSA、Ed25519、SM2 的格式化均改为调用它们(by @gouguolei in e314c99 6ad47b4 0769ea0 2c9ad5a)
  • 简化 RSA 流式验签并移除未使用的流式缓冲区:rsa.StreamVerifier.verify 只返回 error,不再返回一个在无错误时恒为 true 的 valid;unicode.StreamEncoder、unicode.StreamDecoder 去掉未使用的固定 [512]byte 缓冲区;摩斯电码的错误信息改用字符串字面量,不再用没有占位符的 fmt.Sprintf(by @gouguolei in 68dad92)
  • 修正 SetSingMode 的反向断言并显式初始化 SM2 默认值:clamp 测试在调用 SetSingMode(Bytes) 后期望 SingMode 仍为 ASN1,这与 setter 直接赋值的实现相矛盾,而 NewSm2KeyPair 之前依赖零值恰好等于 ASN1;现在构造函数显式设置 SingMode: ASN1,测试同时断言两个方向(by @gouguolei in 079efab)
  • 清理并补充测试:从 24 个测试文件中移除未使用的变量与重复用例,新增 key_format_test.go、key_test.go 覆盖密钥材料辅助函数、各种 UnsupportedKeyFormatError 提示及公开 API 的拒绝路径,并覆盖 SM2 的 DER 与私钥标量区间分支,keypair 语句覆盖率提升至 97.7%(by @gouguolei in 372209d 12c3e11)

🚀 持续集成 ​

  • 新增 golangci-lint 工作流与配置:lint.yml 在向 master 推送和发起 PR 时运行固定为 v2.15.0 的 golangci-lint-action@v9,权限仅 contents: read;.golangci.yml 在标准规则集之外启用 misspell、unconvert、unparam、whitespace,关闭过于主观的 staticcheck 风格检查(ST1000–ST1022、QF1001),并为 errcheck 排除 (io.Seeker).Seek(回卷流按设计是尽力而为);README 以该工作流的状态徽章替换 Go Report Card 徽章(by @gouguolei in 1487675 0517244)

📝 文档 ​

  • README 图片改为从仓库读取,不再依赖文档站:Logo、GVP 与 G-Star 横幅、JetBrains 图标均指向 assets/,中文、英文、日文三个 README 不再依赖 dongle.go-pkg.com(by @gouguolei in 19bffd5)
What's Changed (19)
  • add ASN.1 support by @Web-Coke in #40
  • fix(morse): Add some code from codigomorse.org and correct some repetitive code by @htlsmilework in #42
  • Decode the ascii85 z shortcut without truncating by @youdie006 in #44
  • perf(morse): Derive the reverse alphabet once instead of scanning it per symbol by @darakanoit in #46
  • Pad the ascii85 partial group without counting z shortcuts by @youdie006 in #47
  • fix(coding): encode and decode base58 and base62 streams as a whole by @Shaisolaris in #48
  • fix(keypair): correct SingMode test assertion and add explicit default by @gouguolei in 079efab
  • fix(keypair): accept externally generated keys instead of panicking by @gouguolei in 012269d
  • test(keypair): cover error paths and key material helpers by @gouguolei in 12c3e11
  • docs(readme): replace old badge with golangci-lint by @gouguolei in 0517244
  • docs(readme): replace old badge with golangci-lint by @gouguolei in 1487675
  • test: Clean up redundant content and unused variables in the test code by @gouguolei in 372209d
  • test(sm2): DER encoding error branch covering key formatting by @gouguolei in 6ad47b4
  • refactor(keypair): Extract x509 Marshall function as a variable to support testing simulation by @gouguolei in e314c99
  • refactor(crypto): Replace the ed25519 key serialization function with a local implementation by @gouguolei in 0769ea0
  • refactor(rsa): Replace the standard library key serialization function with a custom implementation by @gouguolei in 2c9ad5a
  • refactor(crypto/rsa): Simplify function signatures and clean up redundant code by @gouguolei in 68dad92
  • docs(readme): Replace the golangci lit badge with the GitHub Actions status badge by @gouguolei in e6f8039
  • docs(readme): Replace the image resource reference from remote URL to local assets path by @gouguolei in 19bffd5

v1.2.3 (2025-12-16) ​

✨ 新功能 ​

  • RSA 密钥对可以只持有当前操作需要的那把密钥:RsaKeyPair 新增 Type 字段并配套 SetType 方法,同时新增 KeyType 类型及其 PublicKey、PrivateKey 常量;NewStdEncrypter、NewStdDecrypter、NewStdSigner、NewStdVerifier 与对应的流式实现按密钥类型分派,只持有公钥的密钥对可以加密、验签,只持有私钥的密钥对可以解密、签名,公钥同样可以作为签名方、由私钥验证;Type 为空时按操作自动回退——加密与验签使用 PublicKey,解密与签名使用 PrivateKey;默认填充跟随密钥格式,PKCS1 使用 PKCS1v15,PKCS8 加密使用 OAEP、签名使用 PSS,签名传入 OAEP 或加密传入 PSS 会返回 UnsupportedPaddingSchemeError;crypto/internal/rsa 补齐了公钥与私钥两种方向、每种填充组合的实现,包括 Go 标准库只提供单向接口的 PSS 编码与 MGF1(by @gouguoyin in 12ffe48 eb81cbc 33ac684 749b690)
  • Sm2KeyPair 新增 SetMode 方法,CipherOrder 重命名为 Sm2CipherMode:SetMode 成为选择密文顺序的推荐写法,SetOrder 保留为薄封装以保证已有调用仍可编译;类型重命名只影响显式写出 CipherOrder 的代码,参数名 order 统一改为 mode,不再与密钥顺序的含义混淆(by @gouguoyin in 858d8b8 3785a02 6d30805 56b6b15)

🔧 重构 ​

  • 移除 Sm2KeyPair 的 LoadPublicKey、LoadPrivateKey 方法:SM2 此前是唯一由密钥对自己读取文件的实现,调用方必须传入 fs.File;现在改为自行读取文件后调用 SetPublicKey / SetPrivateKey,与 RSA、Ed25519 保持一致(by @gouguoyin in e4d6e3c)
  • 将 crypto/sm2 拆分为 encrypt.go、decrypt.go、sign.go、verify.go,内部辅助函数重命名为 EncryptWithPublicKey、DecryptWithPrivateKey、SignWithPrivateKey、VerifyWithPublicKey,函数需要哪把密钥在调用处一眼可见;同时删除冗余的 SM2 实现、把辅助函数拆到独立文件,priv 字段更名为 pri 以与包内其他命名一致(by @gouguoyin in 86819de 1602745 0dfd8ea c0a45e4 ccc968f f876923)
  • 缓存 Ed25519 解析后的密钥:签名器与验签器此前每次调用都要解析一次 PEM,并与 crypto/keypair 中已有的解析逻辑重复;现在两者只解析一次并缓存结果,重复代码被删除,包内文件拆分为 ed25519.go、sign.go、verify.go(by @gouguoyin in 0ed7ca5)
  • 删除 RC4 回退分支中冗余的 cipher 创建:该分支创建的 cipher 立即被丢弃(by @gouguoyin in 9320875)
What's Changed (18)
  • refactor(ed25519): Remove duplicate key parsing logic and use caching to improve performance by @gouguoyin in 0ed7ca5
  • refactor(rc4): Delete the redundant code for creating cipher in fallback by @gouguoyin in 9320875
  • chore(sm2): Remove redundant implementation and modularize the splitting function to independent files by @gouguoyin in 86819de
  • refactor(sm2): priv -> pri by @gouguoyin in f876923
  • feat(rsa): Provide signature generation and verification methods based on public and private keys by @gouguoyin in 749b690
  • feat(keypair): Add key type definition to distinguish between public and private keys by @gouguoyin in 12ffe48
  • feat(rsa): Add a Type field in the RsaKeyPair structure to specify the key type by @gouguoyin in eb81cbc
  • feat(rsa): Add support for public key encryption and private key decryption by @gouguoyin in 33ac684
  • refactor(sm2): Remove the CipherOrder type definition and replace it with a string constant by @gouguoyin in 3785a02
  • refactor(sm2): Delete the 'LoadPublicKey' and 'LoadPrivateKey' methods by @gouguoyin in e4d6e3c
  • refactor(sm2): Decrypt -> DecryptWithPrivateKey by @gouguoyin in 1602745
  • refactor(sm2): Encrypt -> EncryptWithPublicKey by @gouguoyin in 0dfd8ea
  • refactor(sm2): Sign -> SignWithPrivateKey by @gouguoyin in c0a45e4
  • refactor(sm2): Verify -> VerifyWithPublicKey by @gouguoyin in ccc968f
  • refactor(sm2): Change the function parameter name from 'order' to 'mode' by @gouguoyin in 6d30805
  • feat(crypto): Add SetMode method to replace the existing SetOrder method by @gouguoyin in 858d8b8
  • refactor(sm2): Rename the Order parameter to Mode by @gouguoyin in 56b6b15
  • docs(utils): Update Int2Bytes function comments by @gouguoyin in 3d22896

v1.2.2 (2025-12-08) ​

✨ 新功能 ​

  • 为链式 API 增加 SM2 签名与验签能力:新增 Signer.BySm2 与 Verifier.BySm2,标准处理和流式处理均支持,SM2 与 RSA、Ed25519 一样可以在同一条链上用私钥签名、用公钥验签;Sm2KeyPair.SetUID 用于设置参与 ZA 计算的用户标识,未设置时保持 1234567812345678;验签时签名为空会在进入曲线运算前直接返回 EmptySignatureError(by @gouguoyin in b72066e 0382cd6 39d00c3)
  • 增加 RSA 填充方案选择:新增 RsaPaddingScheme 类型,提供 PKCS1v15、OAEP、PSS 三种填充,通过 SetPadding 指定;PKCS1v15 可用于加密与签名,OAEP 仅用于加密且需要通过 SetHash 指定哈希,PSS 仅用于签名;未显式设置时按密钥格式回退,PKCS1 密钥使用 PKCS1v15、PKCS8 密钥使用 OAEP,不支持的组合返回 UnsupportedPaddingSchemeError 而不是标准库的笼统错误(by @gouguoyin in d1734dc b4173be d08e5fc)
  • 新增一组细分的密钥与签名错误类型:EmptyPrivateKeyError、EmptyFormatError、UnsupportedKeyFormatError、EmptyPaddingError、UnsupportedPaddingSchemeError、EmptySignatureError 取代原先的笼统错误,调用方可以区分「密钥为空」和「密钥格式错误」(by @gouguoyin in 856dd51)

🐛 修复 ​

  • 修复私钥为 PKCS#8 格式时无法解密 PKCS#1 v1.5 密文的问题(#39):当 Format 为 PKCS8 且未显式设置填充时,解密默认走 OAEP,导致 JSEncrypt 或 PHP openssl_* 默认填充产生的密文报 crypto/rsa: decryption error,而同样的密文 PHP 自己却能解开;现在可通过 SetPadding 指定填充,报告中使用的密钥对也保留为回归测试(by @gouguoyin in 27c69f6)
  • 移除 RSA 验签中冗余的签名长度检查:该检查会在 rsa.Verify* 校验之前就把其他库生成的合法签名拒掉,而标准库本身对长度错误的签名已有明确报错(by @gouguoyin in faa99bb)

⚡ 性能优化 ​

  • 摩斯编码、解码返回结果时少一次拷贝:[]byte(builder.String()) 改为 utils.String2Bytes,直接复用 builder 的缓冲区而不再多复制一份,对输出本身已是大头的场景收益明显(by @gouguoyin in 10d2eb0)

🔧 重构 ​

  • 按算法重命名密钥格式与密文顺序类型:KeyFormat 改为 RsaKeyFormat,CipherOrder 改为 Sm2CipherOrder,不再使用看起来像对所有算法都生效的通用名;NoSignatureError 改为 EmptySignatureError,UnsupportedPemTypeError 改为 UnsupportedKeyFormatError,Ed25519KeyPair.Sign 改为 Signature(by @gouguoyin in 37d5a1a ac77cf7 6135756 8a6ea39)
  • 重写 RSA 加解密与签名验签逻辑:每种操作在创建加密器、解密器、签名器、验签器时一次性确定填充方案并按方案分派,PSS 被用于加密、OAEP 缺少哈希等情况在构造时就会报错,而不是在流处理中途失败(by @gouguoyin in d08e5fc)
  • 重命名各流式解密器的字段:decrypted 改为 buffer、pos 改为 position,覆盖 3DES、AES、Blowfish、DES、Tea、XTea、Twofish、SM4 与 Salsa20,同时简化 3DES 流式解密的数据切分逻辑(by @gouguoyin in 114d3be efefe59 e66e508 ba303e7 4d93579 e0b9f3b 5f311b4 426506a f375496 ce101f1)
  • Ed25519 的 StdSigner、StdVerifier 改为按值持有密钥对:不再持有指针,构造之后外部修改密钥对不会影响正在进行的操作,同时简化 Ed25519 的错误类型(by @gouguoyin in b5cd502 225b70f)
  • 将 mock、utils 移入 internal:测试辅助包与零拷贝辅助函数不再对外暴露,SM4 实现同时迁入 crypto/internal/sm4(by @gouguoyin in ef82486 fe841a7)
  • 内部 sm2curve 包重命名为 sm2,并把 stdAsn1 别名统一为其他文件使用的 encodingAsn1(by @gouguoyin in 14e9818 cf69603)
  • 简化测试:用 internal/mock 的 mock.File 取代各测试中重复实现的 reader mock,所有测试文件补上打开文件的关闭操作,中文注释统一改为英文(by @gouguoyin in 6b021d7 3ea3710 bd8b1b3 7fb2ddc 9a4b693 2cab5e7 bbc4123 ee77460)

📝 文档 ​

What's Changed (38)

v1.2.1 (2025-11-24) ​

✨ 新功能 ​

  • 增加 Sm2 非对称椭圆曲线加密算法对 BIT_STRING 格式密钥直接解析支持

🐛 修复 ​

  • 修复 Sm2 非对称椭圆曲线加密算法中 wNAF 算法错误造成某些情况下解密失败的 bug

⚡ 性能优化 ​

  • 优化 Sm2 非对称椭圆曲线加密算法中曲线域元素运算实现

🔧 重构 ​

  • 简化测试循环语法,从 for 循环改为 range 循环
What's Changed (12)
  • refactor(sm2curve): pointFelem -> pointField by @gouguoyin in eb6878e
  • test(sm2): Change the declaration method of empty byte slices from literal to var declaration by @gouguoyin in 38a86c8
  • style(sm2curve): Add necessary comments by @gouguoyin in 27497c7
  • Potential fix for code scanning alert no. 1: Workflow does not contain permissions (#33) by kuafuRace in 9bab6c9
  • Add direct parsing of hexadecimal key pairs for SM2 (#32) by @WebChang in a4509b6
  • Fix the wNAF algorithm (#36) by @WebChang in 73911e8
  • fix(crypto): Introduce a rewritable parseDerPrivatKeyFunc variable to support test simulation by @gouguoyin in d61fe04
  • test(sm2): Improve unit testing coverage to 100% by @gouguoyin in 7b2ddf3
  • chore(version): Update version number to 1.2.1 by @gouguoyin in 31d1ee7
  • Add issue unit test (#38) by @WebChang in b91161c
  • fix(sm2curve): Fix SM2 curve domain element subtraction and borrowing processing by @gouguoyin in 1164b55
  • fix(sm2): Add issue #34 unit test by @gouguoyin in b86b4dd

v1.2.0 (2025-11-11) ​

✨ 新功能 ​

  • RSAKeyPair 结构体增加 FormatPublicKey 和 FormatPrivateKey 方法,用于将 base64 编码的 der 格式的 RSA 公钥和私钥格式化成 pem 格式
  • Ed25519KeyPair 结构体增加 FormatPublicKey和 FormatPrivateKey 方法,用于将 base64 编码的 der 格式的 Ed25519 公钥和私钥格式化成 pem 格式
  • RSAKeyPair 结构体增加 CompressPublicKey 和 CompressPrivateKey 方法,用于将 pem 格式的 RSA 公钥和私钥压缩成经过 base64 编码的 der 格式
  • Ed25519KeyPair 结构体增加 CompressPublicKey和 CompressPrivateKey 方法,用于将 pem 格式的 Ed25519 公钥和私钥压缩成经过 base64 编码的 der 格式
  • 增加 Sm2 非对称椭圆曲线加密算法支持,包括标准处理和流式处理

⚡ 性能优化 ​

  • 优化编码器和解码器性能,重用读缓冲区,减少内存分配和复制

🔧 重构 ​

  • 移除 RSAKeyPair 结构体的 LoadPublicKey 和 LoadPrivateKey 方法
  • 移除 Ed25519KeyPair 结构体的 LoadPublicKey 和 LoadPrivateKey 方法
  • RSAKeyPair 结构体的 GenKeyPair, SetPublicKey, SetPrivateKey 方法从无返回值改为返回 error
  • Ed25519KeyPair 结构体的 GenKeyPair, SetPublicKey, SetPrivateKey 方法从无返回值改为返回 error
What's Changed (25)
  • chore(dongle): Update package meta and version number by @gouguoyin in ab46cdb
  • feat(mock): Add Error WriteAfterN struct, which supports returning an error after a specified number of writes by @gouguoyin in a92350f
  • test(style): Unify unit test case Name by @gouguoyin in fda8e09
  • fix(cipher): Change the return value of empty input from src to []byte{} by @gouguoyin in 81d8e29
  • feat(sm2curve): Implement SM2-P-256 elliptic curve and ASN.1 encoding and decoding for sm2 by @gouguoyin in 8120c6b
  • perf(base32): Optimize the performance of streaming codecs by @gouguoyin in df8bc9f
  • perf(base45):Optimize the performance of base45 encoding and decoding by @gouguoyin in 15669d5
  • refactor(base58): Optimize the implementation of stream encoders and decoders by @gouguoyin in 70b7b7b
  • refactor(base62): Optimize the implementation of stream encoders and decoders by @gouguoyin in 2de952d
  • perf(base64): Optimize the implementation of stream encoders and decoders by @gouguoyin in 94575a1
  • refactor(base85): Optimize the implementation of stream encoders and decoders by @gouguoyin in 5c03d1a
  • perf(base91): Optimize encoding and decoding performance by @gouguoyin in bcff90c
  • perf(base100): Optimize the implementation of stream encoders and decoders by @gouguoyin in 058877c
  • refactor(morse): Optimize the buffer usage of streaming decoders by @gouguoyin in a52a536
  • feat(unicode): Optimize the buffer usage of streaming decoders by @gouguoyin in dd27319
  • feat(crypto): Add FormatPublicKey,FormatPrivateKey, CompressPublicKey, CompressPrivateKey methods by @gouguoyin in e947625
  • feat(crypto): Add EmptyPublicKeyError and EmptyPrivateKeyError by @gouguoyin in c844db5
  • refactor(keypair): Add CipherOrder type to control the order of SM2 ciphertext components by @gouguoyin in e3d8df9
  • feat(sm2): Add support for SM2 asymmetric elliptic curve encryption algorithm by @gouguoyin in dfa2a45
  • perf(md2): Optimize the performance of MD2 hash algorithm by @gouguoyin in 380718a
  • perf(sm3): Optimize the performance of SM3 hash algorithm by @gouguoyin in 9b1e3ed
  • docs(readme): Add playground link url by @gouguoyin in c4fac75
  • docs: Update the annotation explanation in AES symmetric encryption algorithm by @gouguoyin in 4adf429
  • refactor(sm2curve): Refactor the SM2 curve implementation to improve performance and maintainability by @gouguoyin in 10eefe2
  • refactor(crypto): MarshalPKCS8 -> MarshalPKCS8PrivateKey, MarshalSPKI ->MarshalSPKIPublicKey by @gouguoyin in ef63d93

v1.1.8 (2025-11-05) ​

✨ 新功能 ​

  • 增加 Unicode 编码解码支持,包括标准处理和流式处理
  • 对称分组加密算法增加 TBC 填充模式支持

🐛 修复 ​

  • 修复 *RsaKeyPair.formatPublicKey 和 *RsaKeyPair.formatPrivateKey 格式化密钥失败的 bug
  • 修复 *Ed25519KeyPair.formatPublicKey 和 *Ed25519KeyPair.formatPrivateKey 格式化密钥失败的 bug
  • 修复解密时对编码过的密文解码失败后无法获取错误的 bug

🔧 重构 ​

  • 对称分组加密算法中默认填充模式从 PKCS7 改为 No
What's Changed (36)

v1.1.7 (2025-10-20) ​

✨ 新功能 ​

  • 增加 sm4 中国国家标准分组加密算法支持,包括标准处理和流式处理,支持不同分块模式和填充模式

🐛 修复 ​

  • 修复非对称数字签名算法中验签错误的 bug #30
  • 优化流式处理逻辑,添加对 reader 位置重置的支持,确保从数据源的开头开始读取,避免因之前读取操作导致的位置偏移问题,保证流式操作的完整性和正确性

🔧 重构 ​

  • crypto/cipher/block.go 中 newXXXEncrypter 和 newXXXDecrypter 系列私有方法更改成公开方法 NewXXXEncrypter 和 NewXXXDecrypter
  • crypto/cipher/padding.go 中 newXXXPadding 和 newXXXUnPadding 系列私有方法更改成公开方法 NewXXXPadding 和 NewXXXUnPadding
What's Changed (38)

v1.1.6 (2025-10-12) ​

✨ 新功能 ​

  • 优化 tea 加密算法,支持不同分块模式和填充模式
  • 增加 xtea 加密算法支持,包括标准处理和流式处理

🔧 重构 ​

  • 使用 io.CopyBuffer 简化流式处理逻辑
What's Changed (26)
  • docs(readme): Update the import path in README.cn.md by @gouguoyin in dbe8da4
  • refactor: Rename the util package to utils by @gouguoyin in 9c4122e
  • refactor(cipher): decrypted -> paddedDst by @gouguoyin in 4537c96
  • refactor(mock): Unify the naming of receivers in error file simulation by @gouguoyin in def9c0a
  • refactor(mock): Move package comment from file.go to doc.go by @gouguoyin in 0a86b4a
  • refactor(utils): Add package comment in doc.go by @gouguoyin in d625676
  • style: Add necessary notes by @gouguoyin in 35ed473
  • docs: Add package comments by @gouguoyin in 08ddc95
  • chore(encoder):Optimize error handling logic by @gouguoyin in 6b723b5
  • chore(coding): Unify the naming of error handling variables and optimize the reading logic by @gouguoyin in 3d16e0f
  • chore(crypto): Unify the naming of error handling variables and optimize the reading logic by @gouguoyin in ca35d52
  • test: Add test case for issue #28 by @gouguoyin in b87981c
  • build: Update version number to 1.1.6 by @gouguoyin in 4a16814
  • refactor(hash): Use io.CopyBuffer to replace manual reading of the buffer, simplifying the implementation of stream and hmac methods by @gouguoyin in cf399b5
  • fix(blowfish): Fix the return value counting logic after encrypted data is written by @gouguoyin in 70ea1f7
  • refactor(ed25519): Remove redundant random number generator by @gouguoyin in 6c974f4
  • fix(rsa): Optimize RSA key parsing logic and fix return value handling by @gouguoyin in 6ca625c
  • feat(crypto): Use io.CopyBuffer to improve the performance and efficiency of stream processing readability and fixing potential read error issues by @gouguoyin in b1d4247
  • refactor(decoder):Simplify streaming process with io.CopyBuffer by @gouguoyin in bc1c6ab
  • refactor(encoder):Simplify streaming process with io.CopyBuffer by @gouguoyin in 730c151
  • feat(crypto/tea): Optimize the tea algorithm to support different blocking and padding modes by @gouguoyin in 817e4c5
  • feat(crypto/xtea): Add support for xtea algorithm by @gouguoyin in 6cc0c01
  • test(3des): Remove useless and erroneous tests by @gouguoyin in 2df56d8
  • test: Replace the existing custom errorCloser with CloseErrorWriteCloser from the mock library by @gouguoyin in e70157b
  • feat(cipher): Update the implementation of the TEA encryption algorithm to support block mode by @gouguoyin in b90d008
  • style: Unify the function annotation style and revise some algorithm descriptions by @gouguoyin in 9509d43

v1.1.5 (2025-10-01) ​

🐛 修复 ​

  • 修复对称加密算法中对不需要填充的分组模式(如 CFB/OFB/CTR/GCM 等)进行填充时加解密错误的bug
What's Changed (6)

v1.1.4 (2025-09-23) ​

✨ 新功能 ​

  • 增加 twofish 加密算法支持,包括标准处理和流式处理

🔧 重构 ​

  • 将方法接受者从指针改成值,防止出现使用全局默认实例时属性污染现象,调用方 API 没有任何影响
What's Changed (5)

v1.1.3 (2025-09-15) ​

✨ 新功能 ​

  • 更新 testify 依赖至 v1.11.1

🐛 修复 ​

  • 优化 3DES 对称加密算法对 16 字节密钥的兼容
  • 优化 DES 对称加密算法对不支持的 GCM 模式的校验
  • 优化 3DES 对称加密算法对不支持的 GCM 模式的校验
  • 优化 Blowfish 对称加密算法对不支持的 GCM 模式的校验

🔧 重构 ​

  • 增加 Salsa20 加密算法支持,包括标准处理和流式处理
What's Changed (21)

v1.1.2 (2025-09-08) ​

✨ 新功能 ​

  • 编码/解码支持通过 coding.BufferSize 全局变量自定义文件流缓冲区大小
  • 加密/解密支持通过 crypto.BufferSize 全局变量自定义文件流缓冲区大小
  • Hash/Hmac 算法支持通过 hash.BufferSize 全局变量自定义文件流缓冲区大小
  • 增加 Blake2b 哈希算法支持,包括 blake2b-256、blake2b-384 和 blake2b-512
  • 增加 Blake2s 哈希算法支持,包括 blake2s-128 和 blake2s-256
  • 增加 ChaCha20 加密算法支持
  • 增加 ChaCha20Poly1305 加密算法支持
What's Changed (24)

v1.1.1 (2025-09-01) ​

✨ 新功能 ​

  • 编码/解码、加密/解密、Hash/Hmac、签名/验签支持真正的流式处理
  • 增加 ED25519 数字签名和验证支持
  • 增加 SM3 哈希算法支持
  • coding/morse/morse.go 增加对空格、标点符号和特殊字符的支持

⚡ 性能优化 ​

  • 当输入数据为空时,直接返回空数据而不执行后续操作

🔧 重构 ​

  • 对称加密算法从 ByXXX(cipher.XXXCipher) 改成 ByXXX(*cipher.XXXCipher)
  • 将工具包名从 utils 改成 util
  • 增加 mock/hash.go 来模拟 hash.Hash 接口的错误
What's Changed (42)
  • docs(readme): Update RSA encryption and decryption example by @gouguoyin in 4094aac
  • refactor: Rename utils package to util by @gouguoyin in 9242991
  • feat(hash): Add support for SM3 hash algorithm by @gouguoyin in 3f6e407
  • refactor(crypto/3des): Refactor 3DES encryptor and decryptor by @gouguoyin in 4ed070e
  • refactor(crypto): Refactor AES encryptor and decryptor by @gouguoyin in 6a3dcf9
  • refactor(crypto): Refactor DES encryptor and decryptor by @gouguoyin in 39193c7
  • refactor(rc4): Change the parameter type of the ByRc4 method from cipher.Rc4Cipher to *cipher.Rc4Cipher by @gouguoyin in 4bcba4e
  • refactor(tea): cipher.TeaCipher -> *cipher.TeaCipher by @gouguoyin in f90f82c
  • refactor(tea): cipher.BlowfishCipher -> *cipher.BlowfishCipher by @gouguoyin in af4db9d
  • refactor(crypto/cipher):Rename the padding function and remove the internal dispatcher by @gouguoyin in e44f321
  • feat(crypto): Add the blockCipher struct and encryption/decryption functionality by @gouguoyin in 0c93355
  • refactor(crypto/cipher): Change the encryptor and decryptor methods to private by @gouguoyin in 4ab52bd
  • refactor(cipher): Refactor the password encoder structure and optimize test cases by @gouguoyin in f904e13
  • refactor(mock): data := []byte{} -> var data []byte by @gouguoyin in 40178d8
  • refactor: Use mock.NewFile instead of strings.NewReader and bytes.NewReader by @gouguoyin in b77f6c3
  • refactor: Use the errors.As function instead of type assertion by @gouguoyin in c4ddfd0
  • feat: Add FromFile method by @gouguoyin in a07314f
  • refactor: []byte{} -> var []byte by @gouguoyin in 01ebf5e
  • test(crypto/cipher): Remove redundant comments by @gouguoyin in e0fb4d0
  • test: TestErrorTypes -> TestRsaErrorTypes by @gouguoyin in cd0a48a
  • refactor(crypto): triple_des -> tripleDes by @gouguoyin in e3add07
  • feat(crypto): Add ED25519 signature and verification methods by @gouguoyin in 39f0ce3
  • refactor(crypto): Update variable naming to use camelCase by @gouguoyin in 50d5d4b
  • perf(crypto): Remove the error checking for the result of hasher.Write by @gouguoyin in 966bdd5
  • refactor(mock): Added mock/hash.go to simulate error conditions of the hash.Hash interface by @gouguoyin in 4e38f79
  • test(coding): Optimize code and add benchmark tests by @gouguoyin in ce64a33
  • test(hash): Optimize code and add benchmark tests by @gouguoyin in a30f570
  • feat: Implement true streaming encoding and decoding by @gouguoyin in 0fdc666
  • feat: Implement true streaming hashing by @gouguoyin in 916d8f3
  • refactor(mock): Improve the Sum method of ErrorHasher and add test cases by @gouguoyin in 913ef51
  • feat(crypto): Refactor the ED25519 stream signature and verification logic to achieve true stream signature and verification by @gouguoyin in 704bdda
  • fix(crypto): Optimize the logic of Close and ReadAll by @gouguoyin in fa1e139
  • refactor(crypto): Refactor the Encrypter.stream method to implement true streaming encryption by @gouguoyin in 71ad312
  • test(rc4): Optimize the test coverage for RC4 by @gouguoyin in 38b2928
  • feat: Implement true streaming encryption and decryption by @gouguoyin in 961dc5d
  • build: Update the version number to 1.1.1 by @gouguoyin in a2c746b
  • feat(morse): Add support for spaces, punctuation marks, and special characters by @gouguoyin in 017497c
  • fix(crypto/3des): Return null data when encrypting or decrypting null data by @gouguoyin in 3145828
  • fix(crypto/aes): Return null data when encrypting or decrypting null data by @gouguoyin in f19243d
  • fix(crypto/blowfish): Return null data when encrypting or decrypting null data by @gouguoyin in e9c1905
  • fix(crypto/des): Return null data when encrypting or decrypting null data by @gouguoyin in 7ad600f
  • test: Use mock.NewFile instead of strings.NewReader and bytes.NewReader by @gouguoyin in c70e218

v1.1.0 (2025-08-23) ​

⚠️ 这是一个破坏性更新版本,请慎重升级,但是强烈建议升级

✨ 新功能 ​

  • 增加对 文件流 编码/解码、加密/解密、Hash/Hmac、签名/验签的支持
  • 新增ByBase32Hex 编码/解码方法
  • base32/base32Hex 编码增加对自定义字符集的支持
  • base45 编码增加对自定义字符集的支持
  • base58 编码增加对自定义字符集的支持
  • base62 编码增加对自定义字符集的支持
  • base64/base64Url 编码增加对自定义字符集的支持

🔧 重构 ​

  • 删除 BySafeURL 编码/解码方法
  • 删除 Sm3 哈希算法(hash)和消息认证码算法(hmac)
  • 重命名 ByBase64URL 编码/解码方法为 ByBase64Url
  • 哈希算法(hash)调用方式从 dongle.Encrypt.ByXXX() 改成 dongle.Hash.ByXXX()
  • 消息认证码算法(hmac)调用方式从 dongle.Encrypt.ByHmacXXX() 改成 dongle.Hash.WithKey().ByXXX()
  • 重构 AES, DES, 3DES, Blowfish 等对称加密/解密方法,统一使用 cipher.NewXXXCipher()
  • 重构 RSA 等非对称加密/解密方法,统一使用 keypair.NewXXXKeyPair()
What's Changed (55)

v1.0.1 (2024-11-22) ​

✨ 新功能 ​

  • base62 支持自定义编码表

🐛 修复 ​

  • 修复 AES-CBC-PKCS5 加密解密错误的 bug

🔧 重构 ​

  • 优化代码质量和组织结构
  • 删除 errors.go 文件,将错误信息迁移到各个文件里
  • 统一单元测试格式
  • 移除中文注释
What's Changed (22)

v1.0.0 (2024-11-11) ​

🐛 修复 ​

  • 修复了 AES/ECB/PKCS5 填充导致的 panic

📝 文档 ​

  • 更改了仓库和徽章 URL
What's Changed (5)

有关更早版本的更新日志,请参阅 releases

基于 MIT 许可发布,未经许可禁止任何形式的转载