Comments (8)
最终的密文构造是按 C1,C3,C2顺序返回的
def encrypt(self, plain: bytes, uid: bytes) -> bytes:
"""Encrypt.
Args:
plain: Plain data.
uid: ID of another user.
Returns:
bytes: Cipher data.
Raises:
RequireArgumentError: Missing some required arguments.
"""
if not self.can_encrypt:
raise RequireArgumentError("encrypt", "hid_e", "mpk_e", "mac_klen")
C1, C2, C3 = self._core.encrypt(self._hid_e, self._mpk_e, plain, uid, self._mac_klen)
cipher = bytearray()
cipher.extend(point_to_bytes_1(C1, self._pc_mode))
cipher.extend(C3)
cipher.extend(C2)
return bytes(cipher)
Line 981 in eb537b2
from gmalg.
from gmalg.
from gmalg.
这个是仅仅MAC验证失败,但是明文解密出来了吗?
from gmalg.
两个工具都解不出来,MAC是保证完整性的,MAC验不过,解密过程不会发生。
from gmalg.
方便提供一下你使用的两个验证工具吗?
两个工具都解不出来,MAC是保证完整性的,MAC验不过,解密过程不会发生。
不过完整性校验发生在解密之后,不知道验证工具是否给出了解密后的明文,再提示MAC校验失败,这样我可以排查是密文算错了还是单独MAC算错了
另外你安装的版本是最新的吗?
from gmalg.
https://github.com/zweib730/SM9-misc
https://www.alipan.com/s/JFwwpTh6vQr
我用的最新的1.05版本
from gmalg.
两个工具我都测试了没问题,应该是数据格式的问题
“”算法测试工具——Yaoyuan“都不需要PC字节(主公钥、密文、用户私钥),
”SM9算法验证工具“的密文不能有PC标识字节,并且只需要提供主私钥,并没有用到主公钥和加密私钥(乱填都能解密,因此格式未知)
你可以再试试,应该都是前面那个”04“字节导致的问题,有时候需要有时候不需要,但是 gmalg 里面凡是涉及椭圆曲线点转成字节串的地方都需要PC标识字节。
from gmalg.
Related Issues (9)
- sm2的实现有两个问题 HOT 17
- SM2由私钥计算公钥的实现不对 HOT 3
- SM2解密相关 HOT 1
- SM2密钥交换 HOT 1
- sm9加密明文的方法结合密钥派生函数的分组密码算法 HOT 1
- sm2密钥交换问题
- sm2私钥计算公钥问题 HOT 2
- 当SM9签名和验签分开在不同请求时,验签失败,请问是什么原因呢? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gmalg.