Skip to content

Commit b188897

Browse files
committed
Bump version to 0.2
1 parent 97f2113 commit b188897

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ $ gem install sm2-crypto
3030

3131
## Usage
3232

33+
### Encrypt and Decrypt
34+
3335
```ruby
3436
require 'sm2_crypto'
3537

3638
# Generate key pair
3739
keypair = OpenSSL::PKey::EC.generate("SM2")
3840
private_key = keypair.private_key.to_s(2)
39-
public_key = keypair.public_key.to_bn.to_s(2)
41+
public_key = keypair.public_key.to_octet_string(:uncompressed)
4042

4143
# Encrypt data
4244
message = "Hello, SM2 encryption!"
@@ -48,6 +50,28 @@ decrypted_message = SM2Crypto.decrypt(private_key, encrypted_data)
4850
puts "Decrypted message: #{decrypted_message}"
4951
```
5052

53+
### Sign and Verify
54+
55+
```ruby
56+
message = "Hello, SM2 signature!"
57+
# get signatrue
58+
sign = SM2Crypto.sign(private_key, message)
59+
# verify signatrue
60+
SM2Crypto.verify(public_key, message, sign)
61+
62+
user_id = "31323334353637383132333435363738" # user_id should be a hex string
63+
# sign with hash and user_id
64+
sign = SM2Crypto.sign(private_key, message, sm3_hash: true, user_id: user_id)
65+
# verify with hash and user_id
66+
SM2Crypto.verify(public_key, message, sign, sm3_hash: true, user_id: user_id)
67+
```
68+
69+
### Get Public Key from Private Key
70+
71+
```ruby
72+
public_key = SM2Crypto.get_public_key(private_key)
73+
```
74+
5175
## Contributing
5276

5377
Contributions to the project are welcome. Please fork the repository, create a feature branch, and submit a pull request. Be sure to add tests and update documentation as needed.

sm2-crypto.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gem::Specification.new do |spec|
44
spec.name = "sm2-crypto"
5-
spec.version = "0.1"
5+
spec.version = "0.2"
66
spec.authors = ["Seekr"]
77
spec.email = ["[email protected]"]
88

test/test_sm2_crypto.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_encrypt_and_decrypt_with_padding
4949
def test_generate_keypairs
5050
keypair = OpenSSL::PKey::EC.generate("SM2")
5151
private_key = keypair.private_key.to_s(2)
52-
public_key = keypair.public_key.to_bn.to_s(2)
52+
public_key = keypair.public_key.to_octet_string(:uncompressed)
5353

5454
msg = SecureRandom.random_bytes(rand(10..100))
5555
encrypted_data = SM2Crypto.encrypt(public_key, msg)

0 commit comments

Comments
 (0)