Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
a96cae4f
Unverified
Commit
a96cae4f
authored
Jan 24, 2024
by
Yeuoly
Committed by
GitHub
Jan 24, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refine: faster rsa implement (#2182)
parent
7cb75cb2
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
283 additions
and
4 deletions
+283
-4
gmpy2_pkcs10aep_cipher.py
api/libs/gmpy2_pkcs10aep_cipher.py
+277
-0
rsa.py
api/libs/rsa.py
+4
-3
requirements.txt
api/requirements.txt
+2
-1
No files found.
api/libs/gmpy2_pkcs10aep_cipher.py
0 → 100644
View file @
a96cae4f
This diff is collapsed.
Click to expand it.
api/libs/rsa.py
View file @
a96cae4f
# -*- coding:utf-8 -*-
# -*- coding:utf-8 -*-
import
hashlib
import
hashlib
from
Crypto.Cipher
import
AES
,
PKCS1_OAEP
from
Crypto.Cipher
import
AES
from
Crypto.PublicKey
import
RSA
from
Crypto.PublicKey
import
RSA
from
Crypto.Random
import
get_random_bytes
from
Crypto.Random
import
get_random_bytes
from
extensions.ext_redis
import
redis_client
from
extensions.ext_redis
import
redis_client
from
extensions.ext_storage
import
storage
from
extensions.ext_storage
import
storage
import
libs.gmpy2_pkcs10aep_cipher
as
gmpy2_pkcs10aep_cipher
def
generate_key_pair
(
tenant_id
):
def
generate_key_pair
(
tenant_id
):
private_key
=
RSA
.
generate
(
2048
)
private_key
=
RSA
.
generate
(
2048
)
...
@@ -35,7 +36,7 @@ def encrypt(text, public_key):
...
@@ -35,7 +36,7 @@ def encrypt(text, public_key):
ciphertext
,
tag
=
cipher_aes
.
encrypt_and_digest
(
text
.
encode
())
ciphertext
,
tag
=
cipher_aes
.
encrypt_and_digest
(
text
.
encode
())
rsa_key
=
RSA
.
import_key
(
public_key
)
rsa_key
=
RSA
.
import_key
(
public_key
)
cipher_rsa
=
PKCS1_OAEP
.
new
(
rsa_key
)
cipher_rsa
=
gmpy2_pkcs10aep_cipher
.
new
(
rsa_key
)
enc_aes_key
=
cipher_rsa
.
encrypt
(
aes_key
)
enc_aes_key
=
cipher_rsa
.
encrypt
(
aes_key
)
...
@@ -58,7 +59,7 @@ def get_decrypt_decoding(tenant_id):
...
@@ -58,7 +59,7 @@ def get_decrypt_decoding(tenant_id):
redis_client
.
setex
(
cache_key
,
120
,
private_key
)
redis_client
.
setex
(
cache_key
,
120
,
private_key
)
rsa_key
=
RSA
.
import_key
(
private_key
)
rsa_key
=
RSA
.
import_key
(
private_key
)
cipher_rsa
=
PKCS1_OAEP
.
new
(
rsa_key
)
cipher_rsa
=
gmpy2_pkcs10aep_cipher
.
new
(
rsa_key
)
return
rsa_key
,
cipher_rsa
return
rsa_key
,
cipher_rsa
...
...
api/requirements.txt
View file @
a96cae4f
...
@@ -65,4 +65,5 @@ httpx[socks]~=0.24.1
...
@@ -65,4 +65,5 @@ httpx[socks]~=0.24.1
pydub~=0.25.1
pydub~=0.25.1
matplotlib~=3.8.2
matplotlib~=3.8.2
yfinance~=0.2.35
yfinance~=0.2.35
pydub~=0.25.1
pydub~=0.25.1
\ No newline at end of file
gmpy2~=2.1.5
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment