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k
QbEyjw+wQAdxnghLoiHyozYzsZhvbq942bvgDvUCgYBo1t+PdkIq38xp/WH0VrJx
I3DD+6cpOTKy3EqK7wF00Uzep7oYcDrItNCh4QQYXWe6e2535eoemFq8/tPCrNau
0PKVSbebYg8inHzPmuqs3cu0SIFvOaAshy+txtjvXQwVG8tnYpnS0t03Ynpm/0Gp
1s1Ge+115DpNucz3gvu/gwKBgDOM0FC4GGbvPI1jJb4tz3QSA9K+RJmP6HrDXjbe
BtyqYVfmJdvr14KYlGzcW4M+ygefJ/7zLzDZoh0IDSyRNel2sxO6JkNyT/Mou6GV
KUoCGz+wPiKAwtyy5NK2+/SWhozBmBvtzvWLCGhLfIri2BkZGCV1Ddt1h35RIAYt
mGCVAoGAK+IfA2Nkqi09xsU1KPPJTL4P54OsEbE5fNm+hxL1jpfU3cz7VV9X+yvV
fseNn1qkQTvC4JERIypOnkti3xpsWaedP5fHHqveSDeR6ObRRTFcM990EogN9IzE
WOUCpOARkqvdlQO5UwP4fVgJmKERicoHjsuWOf4byZad7FjJYE4=
-----END RSA PRIVATE KEY-----
SOMEDATA777'''
PUBKEY = '''<<<SOMEDATA777
-----BEGIN PUBLIC KEY-----
MIIBCgKCAQEA3bv1e8E+bR53cvDwwwAF3Yhc+g47OvFpmmb0oi/H5xV/u1usUCBq
gC0Apz1CcAAQJM/0TrKF7alfDeAvUD2E0E8SU7UxBHc3Bsn75Gs0wt3kVzqLTBfB
RBW/qVdcNINkAnQUrOJ784OX8bMbH1DtMbvZAoBHFOaEv5G/fUWICBARsEslhSvF
xCXyY4tBwDgPTP1QaF/pzlHhl2L8EVUNNjworEoG897uaDwyJbbShfMlrgZGzEnN
Fr6WYlCsHAlKoWKYq2Duag4ojPV7bh9sVyXCketlZHkYgLb0suw5jZZYuZ42UhPt
QYNKpDmWpnrECkUD6T/1UXTRHvubrKnvywIDAQAB
-----END PUBLIC KEY-----
SOMEDATA777'''
pubkey = rsa.PublicKey.load_pkcs1_openssl_pem(
PUBKEY.encode(),
)
message = 'test'
encode = rsa.encrypt(message, pubkey)
encode = base64.b64encode(encode)
print('ENCRYPTED> ', encode)
Traceback (most recent call last):
File "API_TS.py", line 45, in <module>
pubkey = rsa.PublicKey.load_pkcs1_openssl_pem(
File "/home/ts/.local/lib/python3.8/site-packages/rsa/key.py", line 321, in load_pkcs1_openssl_pem
return cls.load_pkcs1_openssl_der(der)
File "/home/ts/.local/lib/python3.8/site-packages/rsa/key.py", line 336, in load_pkcs1_openssl_der
(keyinfo, _) = decoder.decode(keyfile, asn1Spec=OpenSSLPubKey())
File "/home/ts/.local/lib/python3.8/site-packages/pyasn1/codec/ber/decoder.py", line 1581, in __call__
value, substrate = concreteDecoder.valueDecoder(
File "/home/ts/.local/lib/python3.8/site-packages/pyasn1/codec/ber/decoder.py", line 609, in valueDecoder
component, head = decodeFun(head, componentType, **options)
File "/home/ts/.local/lib/python3.8/site-packages/pyasn1/codec/ber/decoder.py", line 1618, in __call__
raise error.PyAsn1Error(
pyasn1.error.PyAsn1Error: <TagSet object, tags 0:0:2> not in asn1Spec: <PubKeyHeader schema object, tagSet=<TagSet object, tags 0:32:16>, subtypeSpec=<ConstraintsIntersection object>, componentType=<NamedTypes object, types <NamedType object, type oid=<ObjectIdentifier schema object, tagSet <TagSet object, tags 0:0:6>>>, <NamedType object, type parameters=<Null schema object, tagSet <TagSet object, tags 0:0:5>, subtypeSpec <ConstraintsIntersection object, consts <SingleValueConstraint object, consts b''>>, encoding iso-8859-1>>>, sizeSpec=<ConstraintsIntersection object>>
import rsa
import base64
PRIVKEY = '''<<<SOMEDATA777
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEA3bv1e8E+bR53cvDwwwAF3Yhc+g47OvFpmmb0oi/H5xV/u1us
UCBqgC0Apz1CcAAQJM/0TrKF7alfDeAvUD2E0E8SU7UxBHc3Bsn75Gs0wt3kVzqL
TBfBRBW/qVdcNINkAnQUrOJ784OX8bMbH1DtMbvZAoBHFOaEv5G/fUWICBARsEsl
hS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be
BtyqYVfmJdvr14KYlGzcW4M+ygefJ/7zLzDZoh0IDSyRNel2sxO6JkNyT/Mou6GV
KUoCGz+wPiKAwtyy5NK2+/SWhozBmBvtzvWLCGhLfIri2BkZGCV1Ddt1h35RIAYt
mGCVAoGAK+IfA2Nkqi09xsU1KPPJTL4P54OsEbE5fNm+hxL1jpfU3cz7VV9X+yvV
fseNn1qkQTvC4JERIypOnkti3xpsWaedP5fHHqveSDeR6ObRRTFcM990EogN9IzE
WOUCpOARkqvdlQO5UwP4fVgJmKERicoHjsuWOf4byZad7FjJYE4=
-----END RSA PRIVATE KEY-----
SOMEDATA777'''
PUBLKEY = '''<<<SOMEDATA777
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA3bv1e8E+bR53cvDwwwAF3Yhc+g47OvFpmmb0oi/H5xV/u1usUCBq
gC0Apz1CcAAQJM/0TrKF7alfDeAvUD2E0E8SU7UxBHc3Bsn75Gs0wt3kVzqLTBfB
RBW/qVdcNINkAnQUrOJ784OX8bMbH1DtMbvZAoBHFOaEv5G/fUWICBARsEslhSvF
xCXyY4tBwDgPTP1QaF/pzlHhl2L8EVUNNjworEoG897uaDwyJbbShfMlrgZGzEnN
Fr6WYlCsHAlKoWKYq2Duag4ojPV7bh9sVyXCketlZHkYgLb0suw5jZZYuZ42UhPt
QYNKpDmWpnrECkUD6T/1UXTRHvubrKnvywIDAQAB
-----END RSA PUBLIC KEY-----
SOMEDATA777'''
publky = rsa.PublicKey.load_pkcs1_openssl_pem(PUBLKEY)
message = 'test'
encode = rsa.encrypt(message, publky)
encode = base64.b64encode(encode)
print('ENCRYPTED> ', encode)
Traceback (most recent call last):
File "API_TS.py", line 45, in <module>
publky = rsa.PublicKey.load_pkcs1_openssl_pem(PUBLKEY)
File "/home/ts/.local/lib/python3.8/site-packages/rsa/key.py", line 320, in load_pkcs1_openssl_pem
der = rsa.pem.load_pem(keyfile, 'PUBLIC KEY')
File "/home/ts/.local/lib/python3.8/site-packages/rsa/pem.py", line 101, in load_pem
pem_lines = [line for line in _pem_lines(contents, pem_start, pem_end)]
File "/home/ts/.local/lib/python3.8/site-packages/rsa/pem.py", line 101, in <listcomp>
pem_lines = [line for line in _pem_lines(contents, pem_start, pem_end)]
File "/home/ts/.local/lib/python3.8/site-packages/rsa/pem.py", line 75, in _pem_lines
raise ValueError('No PEM start marker "%r" found' % pem_start)
ValueError: No PEM start marker "b'-----BEGIN PUBLIC KEY-----'" found
<!DOCTYPE html>
<html lang="ru" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<style media="screen">
body {background: url(https://html5book.ru/wp-content/uploads/2015/10/background54.png)}
footer {
background: #AAAAAA;
align: bottom;
}
#a1 {
align: center;
text-decoration: none;
outline: none;
display: inline-block;
margin: 10px;
color: white;
box-shadow: 0 0 0 2px white;
padding: 20px 0;
width: 150px;
text-align: center;
text-transform: uppercase;
letter-spacing: 3px;
position: relative;
overflow: hidden;
}
span {
font-family: 'Montserrat', sans-serif;
position: relative;
z-index: 5;
}
#a1:before,
#a1:after {
content: "";
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
#a1:before{
transform: translateX(-100%);
background: white;
transition: transform .3s cubic-bezier(.55,.055,.675,.19);
}
#a1:after {
background: #413ad5;
transform: translateX(100%);
transition: transform .3s cubic-bezier(.16,.73,.58,.62) .3s;
}
#a1:hover:before,
#a1:hover:after {transform: translateX(0);}
#a2 {
align: center;
text-decoration: none;
outline: none;
display: inline-block;
margin: 10px;
color: white;
box-shadow: 0 0 0 2px white;
padding: 20px 0;
width: 150px;
text-align: center;
text-transform: uppercase;
letter-spacing: 3px;
position: relative;
overflow: hidden;
}
span {
font-family: 'Montserrat', sans-serif;
position: relative;
z-index: 5;
}
#a2:before,
#a2:after {
content: "";
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
#a2:before{
transform: translateX(-100%);
background: white;
transition: transform .3s cubic-bezier(.55,.055,.675,.19);
}
#a2:after {
background: #413ad5;
transform: translateX(100%);
transition: transform .3s cubic-bezier(.16,.73,.58,.62) .3s;
}
#a2:hover:before,
#a2:hover:after {transform: translateX(0);}
#a3 {
align: center;
text-decoration: none;
outline: none;
display: inline-block;
margin: 10px;
color: white;
box-shadow: 0 0 0 2px white;
padding: 20px 0;
width: 150px;
text-align: center;
text-transform: uppercase;
letter-spacing: 3px;
position: relative;
overflow: hidden;
}
span {
font-family: 'Montserrat', sans-serif;
position: relative;
z-index: 5;
}
#a3:before,
#a3:after {
content: "";
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
#a3:before{
transform: translateX(-100%);
background: white;
transition: transform .3s cubic-bezier(.55,.055,.675,.19);
}
#a3:after {
background: #413ad5;
transform: translateX(100%);
transition: transform .3s cubic-bezier(.16,.73,.58,.62) .3s;
}
#a3:hover:before,
#a3:hover:after {transform: translateX(0);}
</style>
</head>
<body>
<div align="center">
<a id="a1" href="/AUTH-2/Log_In">Войти</a>
<a id="a2" href="/AUTH-2/Sign_In">Регистрация</a>
<a id="a3" href="/AUTH-2/Sign_Out">Выйти</a>
</div>
<footer>
<h3 align="center">Copyright © 2019-2020 <a href="https://tsecret.net">tsecret.net</a>; <a href="https://accounts.tsecret.net">accounts.tsecret.net<a>. Все права защищены.</h3>
</footer>
</body>
</html>
require('./vendor/autoload.php');
use Encryption\Encryption;
use Encryption\Exception\EncryptionException;
$text = 'The quick brown fox jumps over the lazy dog';
$key = 'secretkey';
try {
$encryption = Encryption::getEncryptionObject();
$iv = $encryption->generateIv();
$encryptedText = $encryption->encrypt($text, $key, $iv);
$decryptedText = $encryption->decrypt($encryptedText, $key, $iv);
printf('Cipher : %s%s', $encryption->getName(), PHP_EOL);
printf('Encrypted: %s%s', $encryptedText, PHP_EOL);
printf('Decrypted: %s%s', $decryptedText, PHP_EOL);
printf('Version : %s%s', Encryption::VERSION, PHP_EOL);
}
catch (EncryptionException) {
echo $e;
}
[18-Sep-2020 07:22:27 Europe/Kiev] PHP Parse error: syntax error, unexpected ')', expecting '|' or variable (T_VARIABLE) in /home/tsecret1/Test-Server/GnuPG/index.php on line 37
И да password_verify я не осилил...