Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Taotao-hu/GmSSL-Python

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

pyGmSSL

pyGmSSL is the Python binding to the GmSSL library.

The Python wrappers of pyGmSSL are very similar to the GmSSL v3 C API. Most class/struct and function names are the same, and the arguments are in the same order. Here is an example of encrypting a block of message by SM4 cipher in both C and Python.

#include <gmssl/sm4.h>
#include <gmssl/rand.h>

unsigned char key[SM4_KEY_SIZE] = "1234567812345678";
rand_bytes(key, sizeof(key));

unsigned char block[SM4_BLOCK_SIZE] = "1234567812345678";

SM4_KEY sm4_key;
sm4_set_encrpt_key(&sm4_key, key);
sm4_encrypt(&sm4_key, block, block);

sm4_set_decrpt_key(&sm4_key, key);
sm4_decrypt(&sm4_key, block, block);

The corresponding Python code:

import GmSSL

sm4_key = GmSSL.SM4_KEY()
sm4_key.set_encrypt_key(b"1234567812345678")
ciphertext = sm4_key.encrypt(b"1234567812345678")

sm4_key.set_decrypt_key(b"1234567812345678")
plaintext = sm4_key.decrypt(ciphertext)

About

Python binding to the GmSSL library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Python 100.0%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.