Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
a7fd156d
"README.md" did not exist on "febf559e5c23fa56c5516e76f51a4ec2271b1285"
Commit
a7fd156d
authored
1 year ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
python: add aesEncrypt, aesDecrypt with password
parent
415e5b56
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
python/opendht.pyx
+20
-0
20 additions, 0 deletions
python/opendht.pyx
python/opendht_cpp.pxd
+2
-0
2 additions, 0 deletions
python/opendht_cpp.pxd
with
22 additions
and
0 deletions
python/opendht.pyx
+
20
−
0
View file @
a7fd156d
...
@@ -462,6 +462,26 @@ cdef class Identity(object):
...
@@ -462,6 +462,26 @@ cdef class Identity(object):
k
.
_key
=
self
.
_id
.
first
k
.
_key
=
self
.
_id
.
first
return
k
return
k
def
aesEncrypt
(
bytes
data
,
str
password
)
->
bytes
:
cdef
size_t
d_len
=
len
(
data
)
cdef
cpp
.
uint8_t
*
d_ptr
=
<
cpp
.
uint8_t
*>
data
cdef
cpp
.
Blob
indat
indat
.
assign
(
d_ptr
,
<
cpp
.
uint8_t
*>
(
d_ptr
+
d_len
))
cdef
cpp
.
Blob
encrypted
=
cpp
.
aesEncrypt
(
indat
,
password
.
encode
())
cdef
char
*
encrypted_c_str
=
<
char
*>
encrypted
.
data
()
cdef
Py_ssize_t
length
=
encrypted
.
size
()
return
encrypted_c_str
[:
length
]
def
aesDecrypt
(
bytes
data
,
str
password
)
->
bytes
:
cdef
size_t
d_len
=
len
(
data
)
cdef
cpp
.
uint8_t
*
d_ptr
=
<
cpp
.
uint8_t
*>
data
cdef
cpp
.
Blob
indat
indat
.
assign
(
d_ptr
,
<
cpp
.
uint8_t
*>
(
d_ptr
+
d_len
))
cdef
cpp
.
Blob
decrypted
=
cpp
.
aesDecrypt
(
indat
,
password
.
encode
())
cdef
char
*
decrypted_c_str
=
<
char
*>
decrypted
.
data
()
cdef
Py_ssize_t
length
=
decrypted
.
size
()
return
decrypted_c_str
[:
length
]
cdef
class
DhtConfig
(
object
):
cdef
class
DhtConfig
(
object
):
cdef
cpp
.
DhtRunnerConfig
_config
cdef
cpp
.
DhtRunnerConfig
_config
def
__init__
(
self
):
def
__init__
(
self
):
...
...
This diff is collapsed.
Click to expand it.
python/opendht_cpp.pxd
+
2
−
0
View file @
a7fd156d
...
@@ -94,6 +94,8 @@ ctypedef vector[uint8_t] Blob
...
@@ -94,6 +94,8 @@ ctypedef vector[uint8_t] Blob
cdef
extern
from
"
opendht/crypto.h
"
namespace
"
dht::crypto
"
:
cdef
extern
from
"
opendht/crypto.h
"
namespace
"
dht::crypto
"
:
ctypedef
pair
[
shared_ptr
[
PrivateKey
],
shared_ptr
[
Certificate
]]
Identity
ctypedef
pair
[
shared_ptr
[
PrivateKey
],
shared_ptr
[
Certificate
]]
Identity
cdef
Identity
generateIdentity
(
string
name
,
Identity
ca
,
unsigned
bits
)
cdef
Identity
generateIdentity
(
string
name
,
Identity
ca
,
unsigned
bits
)
cdef
Blob
aesEncrypt
(
Blob
data
,
string
password
)
except
+
cdef
Blob
aesDecrypt
(
Blob
encrypted
,
string
password
)
except
+
cdef
cppclass
PrivateKey
:
cdef
cppclass
PrivateKey
:
PrivateKey
()
PrivateKey
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment