Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cryptography
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Prajczer Péter
Cryptography
Commits
a8bca5b5
Commit
a8bca5b5
authored
5 years ago
by
Prajczer Péter
Browse files
Options
Downloads
Plain Diff
PY-2019.3.1 <prape@r421-69 Merge branch 'master'
parents
0ca53d06
48fcd0ef
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.idea/misc.xml
+7
-0
7 additions, 0 deletions
.idea/misc.xml
ITKoin_01_Prajczer_Peter.py
+112
-0
112 additions, 0 deletions
ITKoin_01_Prajczer_Peter.py
with
119 additions
and
0 deletions
.idea/misc.xml
0 → 100644
+
7
−
0
View file @
a8bca5b5
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"JavaScriptSettings"
>
<option
name=
"languageLevel"
value=
"ES6"
/>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
project-jdk-name=
"Python 3.5 (venv)"
project-jdk-type=
"Python SDK"
/>
</project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ITKoin_01_Prajczer_Peter.py
0 → 100644
+
112
−
0
View file @
a8bca5b5
from
Crypto.Hash
import
SHA256
from
Crypto.PublicKey
import
RSA
import
json
from
Crypto.Signature
import
pkcs1_15
from
base64
import
b64encode
,
b64decode
from
pprint
import
pprint
class
ITKoin
:
def
__init__
(
self
):
self
.
pending_transactions
=
[]
self
.
unspent_transactions
=
[]
self
.
sender_inputs
=
[]
self
.
chain
=
[]
@staticmethod
def
generate_rsa_key
(
filename
):
# generálj 2048 bites RSA kulcsot
rsakey
=
RSA
.
generate
(
2048
)
# a kulcs publikus része kerüljön ide
rsapublickey
=
rsakey
.
publickey
()
# print(rsakey)
# print(rsakey)
# print(vars(rsakey))
# print(vars(rsakey))
# print(vars(rsakey))
# print(vars(rsapublickey))
# PEM formátumra alakítsd az RSA kulcsot
PEMrsakey
=
rsakey
.
export_key
(
'
PEM
'
)
# print(PEMrsakey)
# PEM formátumra alakítsd a kulcs publikus részét
PEMrsapublickey
=
rsapublickey
.
export_key
(
"
PEM
"
)
# print(PEMrsapublickey)
privatekeyfilename
=
filename
+
'
priv.pem
'
f
=
open
(
privatekeyfilename
,
'
wb
'
)
f
.
write
(
PEMrsakey
)
f
.
close
()
publickeyfilename
=
filename
+
'
pub.pem
'
f
=
open
(
publickeyfilename
,
'
wb
'
)
f
.
write
(
PEMrsapublickey
)
f
.
close
()
def
load_key
(
self
,
filename
):
privatekeyfilename
=
filename
+
'
priv.pem
'
privatekeyfileobject
=
open
(
privatekeyfilename
,
'
r
'
)
privatekeyfilecontent
=
privatekeyfileobject
.
read
()
# print(privatekeyfilecontent)
rsakey
=
RSA
.
import_key
(
privatekeyfilecontent
)
self
.
rsakey
=
rsakey
# pprint(vars(self.rsakey))
rsapublickey
=
rsakey
.
publickey
()
self
.
rsapublickey
=
rsapublickey
# print("haha")
# pprint(vars(self.rsapublickey))
def
load_public_key
(
self
,
filename
):
publickeyfilename
=
filename
+
'
pub.pem
'
publickeyfileobject
=
open
(
publickeyfilename
,
'
r
'
)
publickeyfilecontent
=
publickeyfileobject
.
read
()
# pprint(publickeyfilecontent)
rsakey
=
RSA
.
import_key
(
publickeyfilecontent
)
rsapublickey
=
rsakey
.
publickey
()
self
.
rsapublickey
=
rsapublickey
# pprint(vars(self.rsapublickey))
@staticmethod
def
create_hashobject
(
data
):
stringdump
=
json
.
dumps
(
data
)
# ez nem teljesen korrekt megoldás, de így egyszerű mindent byte stringgé konvertálni
binarydump
=
stringdump
.
encode
()
# hozz létre egy hash objektumot
hashobject
=
SHA256
.
new
()
# töltsd be az objektumba a lenyomatolni kívánt byte stringet
hashhexvalue
=
hashobject
.
update
(
binarydump
)
# print(hashobject)
# print(hashhexvalue)
return
hashobject
def
create_signature
(
self
,
data
):
# hozz létre egy signature objektumot
signatureobject
=
pkcs1_15
.
new
(
self
.
rsakey
)
# az adatot töltsd be egy hash objektumba a create_hashobject(data) használatával
hashobject
=
self
.
create_hashobject
(
data
)
# készítsd el az aláírás értéket a sign függvénnyel
signaturevalue
=
signatureobject
.
sign
(
hashobject
)
print
(
signaturevalue
)
b64signaturevalue
=
b64encode
(
signaturevalue
)
print
(
b64signaturevalue
)
print
(
b64signaturevalue
.
decode
())
return
b64signaturevalue
.
decode
()
def
verify_signature
(
self
,
data
,
b64signaturevalue
,
rsapublickey
):
# hozz létre egy verify objektumot
verifyobject
=
pkcs1_15
.
new
(
rsapublickey
)
# az adatot töltsd be egy hash objektumba a create_hashobject(data) használatával
hashobject
=
self
.
create_hashobject
(
data
)
# dekódold base64 kódolással az aláírás értéket
signaturevalue
=
b64decode
(
b64signaturevalue
)
signatureerror
=
verifyobject
.
verify
(
signaturevalue
,
hashobject
)
# értéke: True, ha az aláírás érvényes
validsignature
=
True
return
validsignature
if
__name__
==
'
__main__
'
:
test_coin
=
ITKoin
()
# test_coin.generate_rsa_key("prajczer")
test_coin
.
load_key
(
"
prajczer
"
)
test_coin
.
load_public_key
(
"
prajczer
"
)
test_coin
.
create_hashobject
(
"
random
"
)
test_coin
.
create_signature
(
'
random
'
)
test_coin
.
verify_signature
(
@fasz
kivan
)
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