Fix Format
This commit is contained in:
parent
4835366a0c
commit
ffb80c5fc3
11 changed files with 298 additions and 360 deletions
|
|
@ -6,7 +6,7 @@
|
|||
#include <iostream>
|
||||
#include <openssl/pem.h>
|
||||
namespace crypto {
|
||||
using big_num_t = util::safe_ptr<BIGNUM, BN_free>;
|
||||
using big_num_t = util::safe_ptr<BIGNUM, BN_free>;
|
||||
//using rsa_t = util::safe_ptr<RSA, RSA_free>;
|
||||
using asn1_string_t = util::safe_ptr<ASN1_STRING, ASN1_STRING_free>;
|
||||
|
||||
|
|
@ -340,23 +340,21 @@ void md_ctx_destroy(EVP_MD_CTX *ctx) {
|
|||
EVP_MD_CTX_destroy(ctx);
|
||||
}
|
||||
|
||||
std::string rand_string(std::size_t bytes)
|
||||
{
|
||||
std::string rand_string(std::size_t bytes) {
|
||||
std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!%&()=-";
|
||||
std::string value = rand(bytes);
|
||||
for (std::size_t i = 0; i != value.size(); ++i) {
|
||||
std::string value = rand(bytes);
|
||||
for(std::size_t i = 0; i != value.size(); ++i) {
|
||||
value[i] = alphabet[value[i] % alphabet.length()];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string hash_hexstr(const std::string_view &plaintext)
|
||||
{
|
||||
std::string hash_hexstr(const std::string_view &plaintext) {
|
||||
sha256_t hashBytes = crypto::hash(plaintext);
|
||||
std::ostringstream hashStream;
|
||||
hashStream << std::hex << std::setfill( '0' );
|
||||
std::for_each( hashBytes.cbegin(), hashBytes.cend(), [&]( int c ) { hashStream << std::setw( 2 ) << c; } );
|
||||
hashStream << std::hex << std::setfill('0');
|
||||
std::for_each(hashBytes.cbegin(), hashBytes.cend(), [&](int c) { hashStream << std::setw(2) << c; });
|
||||
std::string hashString = hashStream.str();
|
||||
return hashString;
|
||||
}
|
||||
}
|
||||
} // namespace crypto
|
||||
Loading…
Add table
Add a link
Reference in a new issue