Skip to content
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

SM2 pubkey.encrypt(xxx)加密报错:AttributeError: '_EllipticCurvePublicKey' object has no attribute 'encrypt' #18

Closed
cybershang opened this issue Nov 17, 2023 · 2 comments

Comments

@cybershang
Copy link

cybershang commented Nov 17, 2023

环境:

  • Github Codespaces(Python 3.10.8)+tongsuopy(1.0.1)
  • Win11(Python 3.11.4)+tongsuopy(1.0.1)

运行样例时报错:AttributeError: '_EllipticCurvePublicKey' object has no attribute 'encrypt'

from tongsuopy.crypto import serialization
from tongsuopy.crypto.asymciphers import ec

msg = b"hello"
key = ec.generate_private_key(ec.SM2())

pem = key.public_key().public_bytes(
    encoding=serialization.Encoding.PEM,
    format=serialization.PublicFormat.SubjectPublicKeyInfo,
)
pubkey = serialization.load_pem_public_key(pem)

ciphertext = pubkey.encrypt(msg)
decrypt_text = key.decrypt(ciphertext)
assert decrypt_text == msg
@dongbeiouba
Copy link
Member

因为1.0.1版本还不包含SM2加解密功能,所以敬请期待1.0.2版本发布,多谢!

@cybershang
Copy link
Author

期待(☆▽☆)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants