mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
AESStream: Added internationalization and SHA256Bin
git-svn-id: svn://ultimatepp.org/upp/trunk@12684 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
e4dd9d19d1
commit
f6dbab2267
7 changed files with 116 additions and 87 deletions
|
|
@ -1,9 +1,17 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
#undef _WIN32
|
||||
#ifdef PLATFORM_WIN32
|
||||
#define OPENSSL_SYS_WINDOWS
|
||||
#define OPENSSL_SYS_WIN32
|
||||
#endif
|
||||
|
||||
#include <openssl/rand.h>
|
||||
#include "AESStream.h"
|
||||
|
||||
#include <AESStream/AESStream.h>
|
||||
|
||||
#define TFILE <AESStream/AESStream.t>
|
||||
#include <Core/t.h>
|
||||
|
||||
|
||||
void AESInit();
|
||||
|
||||
|
|
@ -71,12 +79,12 @@ void AESInit()
|
|||
|
||||
static int hops = 0;
|
||||
if (hops > 1000000)
|
||||
throw "AESInit: Random generator init error";//Ошибка инициализации генератора случайных чисел";
|
||||
throw t_("AESInit: Random generator init error");
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
AESEncoderStream::AESEncoderStream(qword _size, const String &_key) throw (const char *)
|
||||
AESEncoderStream::AESEncoderStream(qword _size, const String &_key) // Deprecated in C++11: throw (const char *)
|
||||
: size (_size)
|
||||
, blocks (_size / AES_BLOCK_SIZE)
|
||||
, blocksDone (0)
|
||||
|
|
@ -93,9 +101,9 @@ AESEncoderStream::AESEncoderStream(qword _size, const String &_key) throw (const
|
|||
iv.Cat(iv0);
|
||||
|
||||
if (_key.GetLength() != 16 && _key.GetLength() != 24 && _key.GetLength() != 32)
|
||||
throw "AESEncoderStream::ctor: Key must be 16, 24 or 32 bytes long";//Неверная длина ключа. Нужно 16, 24 или 32 байт";
|
||||
throw t_("AESEncoderStream::ctor: Key must be 16, 24 or 32 bytes long");
|
||||
if (AES_set_encrypt_key((const unsigned char *) ~_key, _key.GetLength() << 3, &key))
|
||||
throw "AESEncoderStream::ctor: Could not setup AES key. OpenSSL problem?";//Не установился ключ для AES. Проблема в OpenSSL?";
|
||||
throw t_("AESEncoderStream::ctor: Could not setup AES key. OpenSSL problem?");
|
||||
}
|
||||
|
||||
int AESEncoderStream::AddData(const String &s)
|
||||
|
|
@ -183,7 +191,7 @@ String AESEncoderStream::GetEncryptedData()
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
AESDecoderStream::AESDecoderStream(const String &_key) throw (const char *)
|
||||
AESDecoderStream::AESDecoderStream(const String &_key) // Deprecated in C++11: throw (const char *)
|
||||
: size (0L)
|
||||
, sizeDone (0L)
|
||||
, iv (AES_BLOCK_SIZE)
|
||||
|
|
@ -192,9 +200,9 @@ AESDecoderStream::AESDecoderStream(const String &_key) throw (const char *)
|
|||
AESInit();
|
||||
|
||||
if (_key.GetLength() != 16 && _key.GetLength() != 24 && _key.GetLength() != 32)
|
||||
throw "AESDecoderStream::ctor: Key must be 16, 24 or 32 bytes long";//Неверная длина ключа. Нужно 16, 24 или 32 байт";
|
||||
throw t_("AESDecoderStream::ctor: Key must be 16, 24 or 32 bytes long");
|
||||
if (AES_set_decrypt_key((const unsigned char *) ~_key, _key.GetLength() << 3, &key))
|
||||
throw "AESDecoderStream::ctor: Could not setup AES key. OpenSSL problem?";//Не установился ключ для AES. Проблема в OpenSSL?";
|
||||
throw t_("AESDecoderStream::ctor: Could not setup AES key. OpenSSL problem?");
|
||||
}
|
||||
|
||||
int AESDecoderStream::AddData(const String &s)
|
||||
|
|
@ -226,7 +234,7 @@ int AESDecoderStream::AddData(const String &s)
|
|||
return (int) sl;
|
||||
}
|
||||
|
||||
String AESDecoderStream::GetDecryptedData() throw (const char *)
|
||||
String AESDecoderStream::GetDecryptedData() // Deprecated in C++1: throw (const char *)
|
||||
{
|
||||
#pragma pack(push,1)
|
||||
struct AES_CONTAINER_HEADER
|
||||
|
|
@ -247,7 +255,7 @@ String AESDecoderStream::GetDecryptedData() throw (const char *)
|
|||
AES_ecb_encrypt(((const unsigned char *) ~data)+offs, ((unsigned char *) &header)+offs, &key, false);
|
||||
|
||||
if (header.m1+header.m2 != AES_CONTAINER_DWORD_HEADER)
|
||||
throw "Wrong key!";//"Ключ шифрования неверный";
|
||||
throw t_("Wrong key!");
|
||||
|
||||
memcpy(~iv, &(header.iv[0]), AES_BLOCK_SIZE);
|
||||
size = header.size;
|
||||
|
|
@ -277,3 +285,9 @@ String AESDecoderStream::GetDecryptedData() throw (const char *)
|
|||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
const dword AES_CONTAINER_DWORD_HEADER = 0x377FEA9F;
|
||||
|
||||
String SHA256Bin(const char *key) {
|
||||
byte hash32[32];
|
||||
SHA256(hash32, key);
|
||||
return String(hash32, 32);
|
||||
}
|
||||
|
|
@ -2,9 +2,11 @@
|
|||
#define _SSLTest_AESStream_h_
|
||||
|
||||
#include <Core/Core.h>
|
||||
#include <openssl/aes.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#include <openssl/aes.h>
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
String AESRandomString(int length);
|
||||
String AESPadString(const String &s, int l);
|
||||
|
|
@ -13,7 +15,7 @@ String AESPadString(const String &s, int l);
|
|||
class AESEncoderStream
|
||||
{
|
||||
public:
|
||||
AESEncoderStream(qword size, const String &key) throw (const char *);
|
||||
AESEncoderStream(qword size, const String &key); // Deprecated in C++11: throw (const char *);
|
||||
|
||||
int AddData(const String &);
|
||||
|
||||
|
|
@ -48,10 +50,10 @@ inline AESEncoderStream & operator << (AESEncoderStream &stream, const String &s
|
|||
class AESDecoderStream
|
||||
{
|
||||
public:
|
||||
AESDecoderStream(const String &key) throw (const char *);
|
||||
AESDecoderStream(const String &key); // Deprecated in C++11: throw (const char *);
|
||||
|
||||
int AddData(const String &);
|
||||
String GetDecryptedData() throw (const char *); //выброс исключения если ключ неверный
|
||||
String GetDecryptedData(); // Deprecated in C++11: throw (const char *); //выброс исключения если ключ неверный
|
||||
|
||||
qword GetSize() {return size;}
|
||||
|
||||
|
|
@ -79,4 +81,6 @@ inline AESDecoderStream & operator << (AESDecoderStream &stream, const String &s
|
|||
//----------------------------------------------------------------------------------------------
|
||||
extern const dword AES_CONTAINER_DWORD_HEADER;
|
||||
|
||||
String SHA256Bin(const char *key);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
58
bazaar/AESStream/AESStream.t
Normal file
58
bazaar/AESStream/AESStream.t
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#ifdef _MSC_VER
|
||||
#pragma setlocale("C")
|
||||
#endif
|
||||
// AESStream.cpp
|
||||
|
||||
T_("AESInit: Random generator init error")
|
||||
esES("AESInit: Error en la inicializaci\303\263n del generador de n\303\272meros "
|
||||
"aleatorios")
|
||||
frFR("AESInit: Erreur d'initialisation du g\303\251n\303\251rateur de nombres "
|
||||
"al\303\251atoire")
|
||||
ruRU("AESInit: \320\236\321\210\320\270\320\261\320\272\320\260 \320\270\320\275\320\270\321\206\320\270\320\260\320\273\320\270\320\267\320\260\321\206\320\270\320\270 "
|
||||
"\320\263\320\265\320\275\320\265\321\200\320\260\321\202\320\276\321\200\320\260 "
|
||||
"\321\201\320\273\321\203\321\207\320\260\320\271\320\275\321\213\321\205 "
|
||||
"\321\207\320\270\321\201\320\265\320\273")
|
||||
|
||||
T_("AESEncoderStream::ctor: Key must be 16, 24 or 32 bytes long")
|
||||
esES("AESEncoderStream::ctor: La clave ha de tener una longitud de 16, 24 o "
|
||||
"32 bytes")
|
||||
frFR("AESEncoderStream::ctor: La cl\303\251 doit avoir une longueur de 16, 24 "
|
||||
"ou 32 octets")
|
||||
ruRU("AESEncoderStream::ctor: \320\235\320\265\320\262\320\265\321\200\320\275\320\260\321\217 "
|
||||
"\320\264\320\273\320\270\320\275\320\260 \320\272\320\273\321\216\321\207\320\260. "
|
||||
"\320\235\321\203\320\266\320\275\320\276 16, 24 \320\270\320\273\320\270 "
|
||||
"32 \320\261\320\260\320\271\321\202")
|
||||
|
||||
T_("AESEncoderStream::ctor: Could not setup AES key. OpenSSL problem?")
|
||||
esES("AESEncoderStream::ctor: Imposible configurar la clave AES. \302\277Problema "
|
||||
"con OpenSSL?")
|
||||
frFR("AESEncoderStream::ctor: Impossible de configurer la cl\303\251 AES. Probl\303\250me "
|
||||
"avec OpenSSL?")
|
||||
ruRU("AESEncoderStream::ctor: \320\235\320\265 \321\203\321\201\321\202\320\260\320\275\320\276\320\262\320\270\320\273\321\201\321\217 "
|
||||
"\320\272\320\273\321\216\321\207 \320\264\320\273\321\217 AES. \320\237\321\200\320\276\320\261\320\273\320\265\320\274\320\260 "
|
||||
"\320\262 OpenSSL?")
|
||||
|
||||
T_("AESDecoderStream::ctor: Key must be 16, 24 or 32 bytes long")
|
||||
esES("AESDecoderStream::ctor: La clave ha de tener una longitud de 16, 24 o "
|
||||
"32 bytes")
|
||||
frFR("AESDecoderStream::ctor: La cl\303\251 doit avoir une longueur de 16, 24 "
|
||||
"ou 32 octets")
|
||||
ruRU("AESDecoderStream::ctor: \320\235\320\265\320\262\320\265\321\200\320\275\320\260\321\217 "
|
||||
"\320\264\320\273\320\270\320\275\320\260 \320\272\320\273\321\216\321\207\320\260. "
|
||||
"\320\235\321\203\320\266\320\275\320\276 16, 24 \320\270\320\273\320\270 "
|
||||
"32 \320\261\320\260\320\271\321\202")
|
||||
|
||||
T_("AESDecoderStream::ctor: Could not setup AES key. OpenSSL problem?")
|
||||
esES("AESDecoderStream::ctor: Imposible configurar la clave AES. \302\277Problema "
|
||||
"con OpenSSL?")
|
||||
frFR("AESDecoderStream::ctor: Impossible de configurer la cl\303\251 AES. Probl\303\250me "
|
||||
"avec OpenSSL?")
|
||||
ruRU("AESDecoderStream::ctor: \320\235\320\265 \321\203\321\201\321\202\320\260\320\275\320\276\320\262\320\270\320\273\321\201\321\217 "
|
||||
"\320\272\320\273\321\216\321\207 \320\264\320\273\321\217 AES. \320\237\321\200\320\276\320\261\320\273\320\265\320\274\320\260 "
|
||||
"\320\262 OpenSSL?")
|
||||
|
||||
T_("Wrong key!")
|
||||
esES("\302\241Clave erronea!")
|
||||
frFR("Mauvaise cl\303\251!")
|
||||
ruRU("\320\232\320\273\321\216\321\207 \321\210\320\270\321\204\321\200\320\276\320\262\320\260\320\275\320\270\321\217 "
|
||||
"\320\275\320\265\320\262\320\265\321\200\320\275\321\213\320\271")
|
||||
|
|
@ -5,5 +5,6 @@ uses
|
|||
file
|
||||
AESStream.cpp,
|
||||
AESStream.h,
|
||||
AESStream.t,
|
||||
src.tpp;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
topic "Installing OpenSSL";
|
||||
[2 $$0,0#00000000000000000000000000000000:Default]
|
||||
[l288;i1120;a17;O9;~~~.1408;2 $$1,0#10431211400427159095818037425705:param]
|
||||
[a83;*R6 $$2,5#31310162474203024125188417583966:caption]
|
||||
[H4;b83;*4 $$3,5#07864147445237544204411237157677:title]
|
||||
|
|
@ -21,6 +20,7 @@ topic "Installing OpenSSL";
|
|||
[2 $$19,0#53580023442335529039900623488521:gap]
|
||||
[C2 $$20,20#70211524482531209251820423858195:class`-nested]
|
||||
[b50;2 $$21,21#03324558446220344731010354752573:Par]
|
||||
[2 $$0,0#00000000000000000000000000000000:Default]
|
||||
[{_}%EN-US
|
||||
[s2; Installing OpenSSL&]
|
||||
[s5; [* 1. In Linux]&]
|
||||
|
|
@ -74,4 +74,4 @@ Files`\Microsoft Visual Studio 9.0`\VC`\vcvarsall.bat`"`" x86]&]
|
|||
[s5; [* Last steps]&]
|
||||
[s5; 2.6. Add in `"Setup/Build methods/Lib directories`" menu, the
|
||||
directory where out32 and out32dll have been copied.&]
|
||||
[s0; ]
|
||||
[s0; ]]
|
||||
22
bazaar/AESStream/src.tpp/SHA256_en-us.tpp
Normal file
22
bazaar/AESStream/src.tpp/SHA256_en-us.tpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
topic "";
|
||||
[H6;0 $$1,0#05600065144404261032431302351956:begin]
|
||||
[i448;a25;kKO9;2 $$2,0#37138531426314131252341829483370:codeitem]
|
||||
[l288;2 $$3,0#27521748481378242620020725143825:desc]
|
||||
[0 $$4,0#96390100711032703541132217272105:end]
|
||||
[ $$0,0#00000000000000000000000000000000:Default]
|
||||
[{_}
|
||||
[ {{10000@(113.42.0) [s0;%% [*@2;4 SHA`-2 functions]]}}&]
|
||||
[s2; &]
|
||||
[s2;%% Cryptographic hash functions designed for the National Security
|
||||
Agency (NSA). See [^http`:`/`/en`.wikipedia`.org`/wiki`/SHA`-2^ here]
|
||||
for explanation.&]
|
||||
[s2;%% There are SHA example digests for testing [^http`:`/`/en`.wikipedia`.org`/wiki`/Examples`_of`_SHA`_digests^ h
|
||||
ere].&]
|
||||
[s0;i448;a25;kKO9;@(0.0.255) &]
|
||||
[ {{10000F(128)G(128)@1 [s0;%% [* Function List]]}}&]
|
||||
[s1; &]
|
||||
[s2;:SHA256Bin`(const char`*`): [_^String^ String]_[* SHA256Bin]([@(0.0.255) const]_[_^String^ c
|
||||
har`*]_[*@3 key])&]
|
||||
[s3; [%% Returns a String representing the 32 bytes (256 bits) SHA`-2
|
||||
hash of ][*@3 data.]&]
|
||||
[s4;%% ]]
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
topic "";
|
||||
[2 $$0,0#00000000000000000000000000000000:Default]
|
||||
[i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class]
|
||||
[l288;2 $$2,2#27521748481378242620020725143825:desc]
|
||||
[0 $$3,0#96390100711032703541132217272105:end]
|
||||
[H6;0 $$4,0#05600065144404261032431302351956:begin]
|
||||
[i448;a25;kKO9;2 $$5,0#37138531426314131252341829483370:item]
|
||||
[l288;a4;*@5;1 $$6,6#70004532496200323422659154056402:requirement]
|
||||
[l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param]
|
||||
[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam]
|
||||
[b42;2 $$9,9#13035079074754324216151401829390:normal]
|
||||
[{_}
|
||||
[ {{10000@(113.42.0) [s0;%% [*@7;4 SHA`-2 functions]]}}&]
|
||||
[s0;i448;a25;kKO9;@(0.0.255) &]
|
||||
[s0;i448;a25;kKO9;%% Cryptographic hash functions designed for the
|
||||
National Security Agency (NSA). See [^http`:`/`/en`.wikipedia`.org`/wiki`/SHA`-2^ h
|
||||
ere] for explanation.&]
|
||||
[s0;i448;a25;kKO9;%% There are SHA example digests for testing [^http`:`/`/en`.wikipedia`.org`/wiki`/Examples`_of`_SHA`_digests^ h
|
||||
ere].&]
|
||||
[s0;i448;a25;kKO9;@(0.0.255) &]
|
||||
[ {{10000F(128)G(128)@1 [s0;%% [* Function List]]}}&]
|
||||
[s4; &]
|
||||
[s5;:SHA224String`(const String`&`): [_^String^ String]_[* SHA224String]([@(0.0.255) const]_
|
||||
[_^String^ String][@(0.0.255) `&]_[*@3 data])&]
|
||||
[s2; [%% Returns a String representing the 28 bytes (224 bits) SHA`-2
|
||||
hash of ][*@3 data.]&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:SHA224Hex`(const String`&`): [_^String^ String]_[* SHA224Hex]([@(0.0.255) const]_[_^String^ S
|
||||
tring][@(0.0.255) `&]_[*@3 data])&]
|
||||
[s2; [%% Returns an hexadecimal String representing the 28 bytes (224
|
||||
bits) SHA`-2 hash of ][*@3 data.]&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:SHA256String`(const String`&`): [_^String^ String]_[* SHA256String]([@(0.0.255) const]_
|
||||
[_^String^ String][@(0.0.255) `&]_[*@3 data])&]
|
||||
[s2; [%% Returns a String representing the 32 bytes (256 bits) SHA`-2
|
||||
hash of ][*@3 data.]&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:SHA256Hex`(const String`&`): [_^String^ String]_[* SHA256Hex]([@(0.0.255) const]_[_^String^ S
|
||||
tring][@(0.0.255) `&]_[*@3 data])&]
|
||||
[s2; [%% Returns an hexadecimal String representing the 32 bytes (256
|
||||
bits) SHA`-2 hash of ][*@3 data.]&]
|
||||
[s3;%% &]
|
||||
[s4;^String^ &]
|
||||
[s5;:SHA384String`(const String`&`): [_^String^ String]_[* SHA384String]([@(0.0.255) const]_
|
||||
[_^String^ String][@(0.0.255) `&]_[*@3 data])&]
|
||||
[s2; [%% Returns a String representing the 48 bytes (384 bits) SHA`-2
|
||||
hash of ][*@3 data.]&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:SHA384Hex`(const String`&`): [_^String^ String]_[* SHA384Hex]([@(0.0.255) const]_[_^String^ S
|
||||
tring][@(0.0.255) `&]_[*@3 data])&]
|
||||
[s2; [%% Returns an hexadecimal String representing the 48 bytes (384
|
||||
bits) SHA`-2 hash of ][*@3 data.]&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:SHA512String`(const String`&`): [_^String^ String]_[* SHA512String]([@(0.0.255) const]_
|
||||
[_^String^ String][@(0.0.255) `&]_[*@3 data])&]
|
||||
[s2; [%% Returns a String representing the 64 bytes (512 bits) SHA`-2
|
||||
hash of ][*@3 data.]&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:SHA512Hex`(const String`&`): [_^String^ String]_[* SHA512Hex]([@(0.0.255) const]_[_^String^ S
|
||||
tring][@(0.0.255) `&]_[*@3 data])&]
|
||||
[s2; [%% Returns an hexadecimal String representing the 64 bytes (512
|
||||
bits) SHA`-2 hash of ][*@3 data.]&]
|
||||
[s3;%% &]
|
||||
[s0; ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue