- Katılım
- 6 Eyl 2017
- Konular
- 53
- Mesajlar
- 358
- Çözüm
- 1
- Online süresi
- 1mo 8d
- Reaksiyon Skoru
- 169
- Altın Konu
- 1
- TM Yaşı
- 8 Yıl 9 Ay 8 Gün
- Başarım Puanı
- 129
- Yaş
- 32
- MmoLira
- 6,490
- DevLira
- 78
ROHAN2 WORLD 1-120 TR TİPİ OFFICIAL YOHARA, BALATHOR VE AMON! 80. GÜNÜNDE! +10.000 ONLİNE! HİLE VE BOT %100 ENGELLİ HEMEN TIKLA!
Selam arkadaşlar,
Çoğu kaynakta openssl 1.0.x sürümlerinde. Openssl resmi sitesinde geçmiş sürümlerin ciddi açıklarının olduğu yasıyor.
Gerçi metin2 kaynak dosyalarında openssl sadece serverkeyde kullanılıyor bildiğim kadarı ile o yüsden pek bi sararı da olmas.
Yinede güncel openssl için yapmanıs gerekenleri şöyle yasayım;
1-) Openssl 1.1.x(o an ki hangisi güncel ise) makinanisa indirip derleyin libleri oluşturun.
2-) Çıkış lib isimleri eski lib isimlerinden farklı olabilir kaynak kodunusda eski isim ile yeni lib isimlerini değiştirmeyi unutmayın.
3-) Openssl güncellemesi ile libserverkey de ki rsacrypto.cpp de uyumsusluklar mevcut aşağıdaki ile değiştirin;
[CODE lang="cpp" title="RSACrypto.cpp"]#include "RSACrypto.h"
#ifdef _WIN32
#include <atlenc.h>
#endif
#include <assert.h>
#include <openssl/aes.h>
#include <openssl/rsa.h>
#include <openssl/rand.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/engine.h>
#include <openssl/sha.h>
#include <openssl/pem.h>
namespace Security
{
static const char rnd_seed[] = "alsfkdj#$^#Y$JBGVKA()#$J@J#OTJG)(@JG)@GJ)J@$)JG)$JG)GJ#@)G";
class StaticInitializer
{
public:
StaticInitializer()
{
}
~StaticInitializer()
{
RAND_cleanup();
}
void Init()
{
RAND_seed(rnd_seed, sizeof(rnd_seed));
}
};
void InitRandomSeed()
{
static StaticInitializer s;
s.Init();
}
// RSA cryptography
//RSACrypto:
ublicKey:
ublicKey(const unsigned char* n, int nsize, const unsigned char* e, int esize)
//{
// rsa_ = Alloc();
// BIGNUM* tmp = NULL;
// tmp = BN_bin2bn( n, nsize, rsa_->n );
// assert( tmp );
// tmp = BN_bin2bn( e, esize, rsa_->e );
// assert( tmp );
// //#ifdef _DEBUG
// // printf("n:");
// // BN_print_fp(stdout, rsa_->n);
// // printf("");
// // printf("e:");
// // BN_print_fp(stdout, rsa_->e);
// // printf("");
// //#endif
//}
RSACrypto:
ublicKey:
ublicKey(const char* n, const char* e)
{
rsa_ = Alloc();
BN_hex2bn((BIGNUM**)RSA_get0_n(rsa_), n);
BN_hex2bn((BIGNUM**)RSA_get0_e(rsa_), e);
}
RSACrypto:
ublicKey:
ublicKey(RSACrypto:
ublicKey& p)
{
rsa_ = RSA_new();
assert(rsa_);
Copy(rsa_, p.rsa_);
}
RSACrypto:
ublicKey::~PublicKey()
{
Free(rsa_);
rsa_ = NULL;
}
RSACrypto:
ublicKey& RSACrypto:
ublicKey:
perator =(const RSACrypto:
ublicKey& p)
{
if (rsa_)
{
Free(rsa_);
rsa_ = NULL;
}
rsa_ = RSA_new();
assert(rsa_);
Copy(rsa_, p.rsa_);
return *this;
}
//Buffer RSACrypto:
ublicKey::GetN()
//{
// if ( rsa_ )
// {
// int len = BN_num_bytes( rsa_->n );
// Buffer n = Buffer::Alloc( len );
// if ( NULL == n.buf )
// {
// return Buffer();
// }
// BN_bn2bin( rsa_->n, (unsigned char *)n.buf );
// return n;
// }
// return Buffer();
//}
//Buffer RSACrypto:
ublicKey::GetE()
//{
// if ( rsa_ )
// {
// int len = BN_num_bytes( rsa_->e );
// Buffer e = Buffer::Alloc( len );
// if ( NULL == e.buf )
// {
// return Buffer();
// }
// BN_bn2bin( rsa_->e, (unsigned char *)e.buf );
// return e;
// }
// return Buffer();
//}
RSACrypto:
ublicKey:
ublicKey() : rsa_(NULL)
{
}
RSA* RSACrypto:
ublicKey::Alloc()
{
RSA* rsa = RSA_new();
assert(rsa);
RSA_set0_key(rsa, BN_new(), BN_new(), BN_new());
return rsa;
}
void RSACrypto:
ublicKey::Free(rsa_st* p)
{
if (p)
{
RSA_free(p);
}
}
void RSACrypto:
ublicKey::Copy(rsa_st* to, const rsa_st* from)
{
BN_copy((BIGNUM*)RSA_get0_n(to), RSA_get0_n(from));
BN_copy((BIGNUM*)RSA_get0_e(to), RSA_get0_e(from));
}
RSACrypto:
rivateKey:
rivateKey() : rsa_(NULL)
{
}
RSACrypto:
rivateKey:
rivateKey(rsa_st* rsa) : rsa_(rsa)
{
}
RSACrypto:
rivateKey::~PrivateKey()
{
if (rsa_)
{
RSA_free(rsa_);
rsa_ = NULL;
}
}
RSA* RSACrypto:
rivateKey::Alloc()
{
RSA* rsa = RSA_new();
assert(rsa);
RSA_set0_key(rsa, BN_new(), BN_new(), BN_new());
RSA_set0_factors(rsa, BN_new(), BN_new());
return rsa;
}
Buffer RSACrypto::EncryptPublic(const RSACrypto:
ublicKey* k, const unsigned char* plain, int plainLen)
{
int rsaSize = RSA_size(k->rsa_);
Buffer cipherText = Buffer::Alloc(rsaSize);
if (NULL == cipherText.buf)
{
return Buffer();
}
// must be checked when RSA_PKCS1_OAEP_PADDING mode
if (plainLen >= rsaSize - 41)
{
Buffer::Free(cipherText);
assert(false);
return Buffer();
}
int cipherTextLen = RSA_public_encrypt(
plainLen,
plain,
(unsigned char*)cipherText.buf,
k->rsa_,
RSA_PKCS1_OAEP_PADDING);
if (-1 == cipherTextLen)
{
Buffer::Free(cipherText);
return Buffer();
}
assert(cipherTextLen == rsaSize);
//XSystem::MemoryPool::MemoryPool_Realloc( cipherText, cipherTextLen );
return cipherText;
}
Buffer RSACrypto:
ecryptPrivate(const RSACrypto:
rivateKey* k, const unsigned char* cipher, int cipherLen)
{
int rsaSize = RSA_size(k->rsa_);
Buffer plainText = Buffer::Alloc(rsaSize);
if (NULL == plainText.buf)
{
return Buffer();
}
int plainTextLen = RSA_private_decrypt(
cipherLen,
cipher,
(unsigned char*)plainText.buf,
k->rsa_,
RSA_PKCS1_OAEP_PADDING);
if (-1 == plainTextLen)
{
Buffer::Free(plainText);
return Buffer();
}
plainText.len = plainTextLen;
return plainText;
}
Buffer RSACrypto::EncryptPrivate(const RSACrypto:
rivateKey* k, const unsigned char* plain, int plainLen)
{
int rsaSize = RSA_size(k->rsa_);
Buffer cipherText = Buffer::Alloc(rsaSize);
if (NULL == cipherText.buf)
{
return Buffer();
}
// must be checked when RSA_PKCS1_PADDING mode (private encrypt¿¡¼´Â ´Ù¸¥ paddingÀ» Áö¿ø¾ÈÇÑ´Ù.)
if (plainLen >= rsaSize - 11)
{
Buffer::Free(cipherText);
assert(false);
return Buffer();
}
int cipherTextLen = RSA_private_encrypt(
plainLen,
plain,
(unsigned char*)cipherText.buf,
k->rsa_,
RSA_PKCS1_PADDING);
if (-1 == cipherTextLen)
{
Buffer::Free(cipherText);
return Buffer();
}
assert(cipherTextLen == rsaSize);
//XSystem::MemoryPool::MemoryPool_Realloc( cipherText, cipherTextLen );
return cipherText;
}
Buffer RSACrypto:
ecryptPublic(const RSACrypto:
ublicKey* k, const unsigned char* cipher, int cipherLen)
{
int rsaSize = RSA_size(k->rsa_);
Buffer plainText = Buffer::Alloc(rsaSize);
if (NULL == plainText.buf)
{
return Buffer();
}
int plainTextLen = RSA_public_decrypt(
cipherLen,
cipher,
(unsigned char*)plainText.buf,
k->rsa_,
RSA_PKCS1_PADDING);
if (-1 == plainTextLen)
{
Buffer::Free(plainText);
return Buffer();
}
plainText.len = plainTextLen;
return plainText;
}
bool RSACrypto::GenerateKey(RSACrypto:
ublicKey* publicKey, RSACrypto:
rivateKey* privateKey)
{
RSA* rsa = RSA_generate_key(1024, 7, NULL, NULL);
if (NULL == rsa)
{
//ERR_get_error();
return false;
}
if (1 != RSA_check_key(rsa))
{
//ERR_get_error();
return false;
}
publicKey->rsa_ = publicKey->Alloc();
publicKey->Copy(publicKey->rsa_, rsa);
privateKey->rsa_ = rsa;
#ifdef _DEBUG
// printf("n:");
// BN_print_fp(stdout, publicKey->rsa_->n);
// printf("");
// printf("e:");
// BN_print_fp(stdout, publicKey->rsa_->e);
// printf("");
//char buf[1024];
//BIO* bp = BIO_new_mem_buf(buf, sizeof(buf));
//PEM_write_bio_RSAPrivateKey(bp, rsa, 0, 0, 0, 0, 0);
//PEM_read_bio_RSAPrivateKey(bp, )
#endif
return true;
}
bool RSACrypto:
rintKey(const PublicKey* k, std::string& e, std::string& n)
{
char* tmp = BN_bn2hex(RSA_get0_e(k->rsa_));
if (!tmp)
{
return false;
}
e = tmp;
tmp = BN_bn2hex(RSA_get0_n(k->rsa_));
if (!tmp)
{
return false;
}
n = tmp;
return true;
}
bool RSACrypto:
rintKey(const PrivateKey* k, std::string& n, std::string& e, std::string& d)
{
char* tmp = BN_bn2hex(RSA_get0_n(k->rsa_));
if (!tmp)
{
return false;
}
n = tmp;
tmp = BN_bn2hex(RSA_get0_e(k->rsa_));
if (!tmp)
{
return false;
}
e = tmp;
tmp = BN_bn2hex(RSA_get0_d(k->rsa_));
if (!tmp)
{
return false;
}
d = tmp;
return true;
}
bool RSACrypto::StorePrivateKey(const PrivateKey* k, char* buf, size_t& buflen)
{
// DER Æ÷¸ËÀ¸·Î º¯È¯
char* tmp = NULL;
int n = i2d_RSAPrivateKey(k->rsa_, (unsigned char**)&tmp);
if (n < 0)
{
return false;
}
if (n > (int)buflen)
{
printf("RSACrypto::StorePrivateKey: buflen is too small\n");
return false;
}
memcpy(buf, tmp, n);
buflen = n;
free(tmp);
return true;
}
bool RSACrypto::RestorePrivateKey(const char* buf, size_t buflen, PrivateKey* k)
{
// DER Æ÷¸Ë¿¡¼ º¯È¯
char* tmp = (char*)malloc(buflen);
if (!tmp)
{
return false;
}
memcpy(tmp, buf, buflen);
if (!d2i_RSAPrivateKey(&k->rsa_, (const unsigned char**)&tmp, buflen))
{
free(tmp);
return false;
}
return true;
}
bool RSACrypto::StorePublicKey(const PublicKey* k, char* buf, size_t& buflen)
{
// DER Æ÷¸ËÀ¸·Î º¯È¯
char* tmp = NULL;
int n = i2d_RSAPublicKey(k->rsa_, (unsigned char**)&tmp);
if (n < 0)
{
return false;
}
if (n > (int)buflen)
{
printf("RSACrypto::StorePublicKey: buflen is too small\n");
return false;
}
memcpy(buf, tmp, n);
buflen = n;
free(tmp);
return true;
}
bool RSACrypto::RestorePublicKey(const char* buf, size_t buflen, PublicKey* k)
{
// DER Æ÷¸Ë¿¡¼ º¯È¯
char* tmp = (char*)malloc(buflen);
if (!tmp)
{
return false;
}
memcpy(tmp, buf, buflen);
if (!d2i_RSAPublicKey(&k->rsa_, (const unsigned char**)&tmp, buflen))
{
free(tmp);
return false;
}
return true;
}
Buffer SHA1:
igest(const Buffer& plain)
{
Buffer result = Buffer::Alloc(20);
::SHA1((const unsigned char*)plain.buf,
(unsigned long)plain.len,
(unsigned char*)result.buf);
return result;
}
}
[/CODE]
Bukadar.
@Koray' müsait samanında konuyu yeşillendirebilir misin?
Çoğu kaynakta openssl 1.0.x sürümlerinde. Openssl resmi sitesinde geçmiş sürümlerin ciddi açıklarının olduğu yasıyor.
Gerçi metin2 kaynak dosyalarında openssl sadece serverkeyde kullanılıyor bildiğim kadarı ile o yüsden pek bi sararı da olmas.
Yinede güncel openssl için yapmanıs gerekenleri şöyle yasayım;
1-) Openssl 1.1.x(o an ki hangisi güncel ise) makinanisa indirip derleyin libleri oluşturun.
2-) Çıkış lib isimleri eski lib isimlerinden farklı olabilir kaynak kodunusda eski isim ile yeni lib isimlerini değiştirmeyi unutmayın.
3-) Openssl güncellemesi ile libserverkey de ki rsacrypto.cpp de uyumsusluklar mevcut aşağıdaki ile değiştirin;
[CODE lang="cpp" title="RSACrypto.cpp"]#include "RSACrypto.h"
#ifdef _WIN32
#include <atlenc.h>
#endif
#include <assert.h>
#include <openssl/aes.h>
#include <openssl/rsa.h>
#include <openssl/rand.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/engine.h>
#include <openssl/sha.h>
#include <openssl/pem.h>
namespace Security
{
static const char rnd_seed[] = "alsfkdj#$^#Y$JBGVKA()#$J@J#OTJG)(@JG)@GJ)J@$)JG)$JG)GJ#@)G";
class StaticInitializer
{
public:
StaticInitializer()
{
}
~StaticInitializer()
{
RAND_cleanup();
}
void Init()
{
RAND_seed(rnd_seed, sizeof(rnd_seed));
}
};
void InitRandomSeed()
{
static StaticInitializer s;
s.Init();
}
// RSA cryptography
//RSACrypto:
ublicKey:
ublicKey(const unsigned char* n, int nsize, const unsigned char* e, int esize)//{
// rsa_ = Alloc();
// BIGNUM* tmp = NULL;
// tmp = BN_bin2bn( n, nsize, rsa_->n );
// assert( tmp );
// tmp = BN_bin2bn( e, esize, rsa_->e );
// assert( tmp );
// //#ifdef _DEBUG
// // printf("n:");
// // BN_print_fp(stdout, rsa_->n);
// // printf("");
// // printf("e:");
// // BN_print_fp(stdout, rsa_->e);
// // printf("");
// //#endif
//}
RSACrypto:
ublicKey:
ublicKey(const char* n, const char* e){
rsa_ = Alloc();
BN_hex2bn((BIGNUM**)RSA_get0_n(rsa_), n);
BN_hex2bn((BIGNUM**)RSA_get0_e(rsa_), e);
}
RSACrypto:
ublicKey:
ublicKey(RSACrypto:
ublicKey& p){
rsa_ = RSA_new();
assert(rsa_);
Copy(rsa_, p.rsa_);
}
RSACrypto:
ublicKey::~PublicKey(){
Free(rsa_);
rsa_ = NULL;
}
RSACrypto:
ublicKey& RSACrypto:
ublicKey:
perator =(const RSACrypto:
ublicKey& p){
if (rsa_)
{
Free(rsa_);
rsa_ = NULL;
}
rsa_ = RSA_new();
assert(rsa_);
Copy(rsa_, p.rsa_);
return *this;
}
//Buffer RSACrypto:
ublicKey::GetN()//{
// if ( rsa_ )
// {
// int len = BN_num_bytes( rsa_->n );
// Buffer n = Buffer::Alloc( len );
// if ( NULL == n.buf )
// {
// return Buffer();
// }
// BN_bn2bin( rsa_->n, (unsigned char *)n.buf );
// return n;
// }
// return Buffer();
//}
//Buffer RSACrypto:
ublicKey::GetE()//{
// if ( rsa_ )
// {
// int len = BN_num_bytes( rsa_->e );
// Buffer e = Buffer::Alloc( len );
// if ( NULL == e.buf )
// {
// return Buffer();
// }
// BN_bn2bin( rsa_->e, (unsigned char *)e.buf );
// return e;
// }
// return Buffer();
//}
RSACrypto:
ublicKey:
ublicKey() : rsa_(NULL){
}
RSA* RSACrypto:
ublicKey::Alloc(){
RSA* rsa = RSA_new();
assert(rsa);
RSA_set0_key(rsa, BN_new(), BN_new(), BN_new());
return rsa;
}
void RSACrypto:
ublicKey::Free(rsa_st* p){
if (p)
{
RSA_free(p);
}
}
void RSACrypto:
ublicKey::Copy(rsa_st* to, const rsa_st* from){
BN_copy((BIGNUM*)RSA_get0_n(to), RSA_get0_n(from));
BN_copy((BIGNUM*)RSA_get0_e(to), RSA_get0_e(from));
}
RSACrypto:
rivateKey:
rivateKey() : rsa_(NULL){
}
RSACrypto:
rivateKey:
rivateKey(rsa_st* rsa) : rsa_(rsa){
}
RSACrypto:
rivateKey::~PrivateKey(){
if (rsa_)
{
RSA_free(rsa_);
rsa_ = NULL;
}
}
RSA* RSACrypto:
rivateKey::Alloc(){
RSA* rsa = RSA_new();
assert(rsa);
RSA_set0_key(rsa, BN_new(), BN_new(), BN_new());
RSA_set0_factors(rsa, BN_new(), BN_new());
return rsa;
}
Buffer RSACrypto::EncryptPublic(const RSACrypto:
ublicKey* k, const unsigned char* plain, int plainLen){
int rsaSize = RSA_size(k->rsa_);
Buffer cipherText = Buffer::Alloc(rsaSize);
if (NULL == cipherText.buf)
{
return Buffer();
}
// must be checked when RSA_PKCS1_OAEP_PADDING mode
if (plainLen >= rsaSize - 41)
{
Buffer::Free(cipherText);
assert(false);
return Buffer();
}
int cipherTextLen = RSA_public_encrypt(
plainLen,
plain,
(unsigned char*)cipherText.buf,
k->rsa_,
RSA_PKCS1_OAEP_PADDING);
if (-1 == cipherTextLen)
{
Buffer::Free(cipherText);
return Buffer();
}
assert(cipherTextLen == rsaSize);
//XSystem::MemoryPool::MemoryPool_Realloc( cipherText, cipherTextLen );
return cipherText;
}
Buffer RSACrypto:
ecryptPrivate(const RSACrypto:
rivateKey* k, const unsigned char* cipher, int cipherLen){
int rsaSize = RSA_size(k->rsa_);
Buffer plainText = Buffer::Alloc(rsaSize);
if (NULL == plainText.buf)
{
return Buffer();
}
int plainTextLen = RSA_private_decrypt(
cipherLen,
cipher,
(unsigned char*)plainText.buf,
k->rsa_,
RSA_PKCS1_OAEP_PADDING);
if (-1 == plainTextLen)
{
Buffer::Free(plainText);
return Buffer();
}
plainText.len = plainTextLen;
return plainText;
}
Buffer RSACrypto::EncryptPrivate(const RSACrypto:
rivateKey* k, const unsigned char* plain, int plainLen){
int rsaSize = RSA_size(k->rsa_);
Buffer cipherText = Buffer::Alloc(rsaSize);
if (NULL == cipherText.buf)
{
return Buffer();
}
// must be checked when RSA_PKCS1_PADDING mode (private encrypt¿¡¼´Â ´Ù¸¥ paddingÀ» Áö¿ø¾ÈÇÑ´Ù.)
if (plainLen >= rsaSize - 11)
{
Buffer::Free(cipherText);
assert(false);
return Buffer();
}
int cipherTextLen = RSA_private_encrypt(
plainLen,
plain,
(unsigned char*)cipherText.buf,
k->rsa_,
RSA_PKCS1_PADDING);
if (-1 == cipherTextLen)
{
Buffer::Free(cipherText);
return Buffer();
}
assert(cipherTextLen == rsaSize);
//XSystem::MemoryPool::MemoryPool_Realloc( cipherText, cipherTextLen );
return cipherText;
}
Buffer RSACrypto:
ecryptPublic(const RSACrypto:
ublicKey* k, const unsigned char* cipher, int cipherLen){
int rsaSize = RSA_size(k->rsa_);
Buffer plainText = Buffer::Alloc(rsaSize);
if (NULL == plainText.buf)
{
return Buffer();
}
int plainTextLen = RSA_public_decrypt(
cipherLen,
cipher,
(unsigned char*)plainText.buf,
k->rsa_,
RSA_PKCS1_PADDING);
if (-1 == plainTextLen)
{
Buffer::Free(plainText);
return Buffer();
}
plainText.len = plainTextLen;
return plainText;
}
bool RSACrypto::GenerateKey(RSACrypto:
ublicKey* publicKey, RSACrypto:
rivateKey* privateKey){
RSA* rsa = RSA_generate_key(1024, 7, NULL, NULL);
if (NULL == rsa)
{
//ERR_get_error();
return false;
}
if (1 != RSA_check_key(rsa))
{
//ERR_get_error();
return false;
}
publicKey->rsa_ = publicKey->Alloc();
publicKey->Copy(publicKey->rsa_, rsa);
privateKey->rsa_ = rsa;
#ifdef _DEBUG
// printf("n:");
// BN_print_fp(stdout, publicKey->rsa_->n);
// printf("");
// printf("e:");
// BN_print_fp(stdout, publicKey->rsa_->e);
// printf("");
//char buf[1024];
//BIO* bp = BIO_new_mem_buf(buf, sizeof(buf));
//PEM_write_bio_RSAPrivateKey(bp, rsa, 0, 0, 0, 0, 0);
//PEM_read_bio_RSAPrivateKey(bp, )
#endif
return true;
}
bool RSACrypto:
rintKey(const PublicKey* k, std::string& e, std::string& n){
char* tmp = BN_bn2hex(RSA_get0_e(k->rsa_));
if (!tmp)
{
return false;
}
e = tmp;
tmp = BN_bn2hex(RSA_get0_n(k->rsa_));
if (!tmp)
{
return false;
}
n = tmp;
return true;
}
bool RSACrypto:
rintKey(const PrivateKey* k, std::string& n, std::string& e, std::string& d){
char* tmp = BN_bn2hex(RSA_get0_n(k->rsa_));
if (!tmp)
{
return false;
}
n = tmp;
tmp = BN_bn2hex(RSA_get0_e(k->rsa_));
if (!tmp)
{
return false;
}
e = tmp;
tmp = BN_bn2hex(RSA_get0_d(k->rsa_));
if (!tmp)
{
return false;
}
d = tmp;
return true;
}
bool RSACrypto::StorePrivateKey(const PrivateKey* k, char* buf, size_t& buflen)
{
// DER Æ÷¸ËÀ¸·Î º¯È¯
char* tmp = NULL;
int n = i2d_RSAPrivateKey(k->rsa_, (unsigned char**)&tmp);
if (n < 0)
{
return false;
}
if (n > (int)buflen)
{
printf("RSACrypto::StorePrivateKey: buflen is too small\n");
return false;
}
memcpy(buf, tmp, n);
buflen = n;
free(tmp);
return true;
}
bool RSACrypto::RestorePrivateKey(const char* buf, size_t buflen, PrivateKey* k)
{
// DER Æ÷¸Ë¿¡¼ º¯È¯
char* tmp = (char*)malloc(buflen);
if (!tmp)
{
return false;
}
memcpy(tmp, buf, buflen);
if (!d2i_RSAPrivateKey(&k->rsa_, (const unsigned char**)&tmp, buflen))
{
free(tmp);
return false;
}
return true;
}
bool RSACrypto::StorePublicKey(const PublicKey* k, char* buf, size_t& buflen)
{
// DER Æ÷¸ËÀ¸·Î º¯È¯
char* tmp = NULL;
int n = i2d_RSAPublicKey(k->rsa_, (unsigned char**)&tmp);
if (n < 0)
{
return false;
}
if (n > (int)buflen)
{
printf("RSACrypto::StorePublicKey: buflen is too small\n");
return false;
}
memcpy(buf, tmp, n);
buflen = n;
free(tmp);
return true;
}
bool RSACrypto::RestorePublicKey(const char* buf, size_t buflen, PublicKey* k)
{
// DER Æ÷¸Ë¿¡¼ º¯È¯
char* tmp = (char*)malloc(buflen);
if (!tmp)
{
return false;
}
memcpy(tmp, buf, buflen);
if (!d2i_RSAPublicKey(&k->rsa_, (const unsigned char**)&tmp, buflen))
{
free(tmp);
return false;
}
return true;
}
Buffer SHA1:
igest(const Buffer& plain){
Buffer result = Buffer::Alloc(20);
::SHA1((const unsigned char*)plain.buf,
(unsigned long)plain.len,
(unsigned char*)result.buf);
return result;
}
}
[/CODE]
Bukadar.
@Koray' müsait samanında konuyu yeşillendirebilir misin?
En Çok Reaksiyon Alan Mesajlar
Öğeyi görmek için üye olmalısınız.
Teşekkürler
Öğeyi görmek için üye olmalısınız.
- Katılım
- 29 Eyl 2009
- Konular
- 1,298
- Mesajlar
- 18,700
- Çözüm
- 203
- Online süresi
- 7mo 19h
- Reaksiyon Skoru
- 9,275
- Altın Konu
- 377
- Başarım Puanı
- 426
- Yaş
- 32
- MmoLira
- 51,370
- DevLira
- 74
Teşekkürler
- Katılım
- 20 Kas 2016
- Konular
- 65
- Mesajlar
- 1,263
- Çözüm
- 12
- Online süresi
- 1mo 3d
- Reaksiyon Skoru
- 619
- Altın Konu
- 0
- TM Yaşı
- 9 Yıl 6 Ay 23 Gün
- Başarım Puanı
- 201
- MmoLira
- 2,443
- DevLira
- 82
Tek tek aradım z varmı diye belki başka yere koymuştur diye ama yok bu olaya çok güldümTeşekkürler
Ekli dosyayı görüntüle 24450



Şu an konuyu görüntüleyenler (Toplam : 0, Üye: 0, Misafir: 0)
Benzer konular
- Cevaplar
- 3
- Görüntüleme
- 392
- Cevaplar
- 10
- Görüntüleme
- 941
- Cevaplar
- 4
- Görüntüleme
- 533









