CryptoSys PKI  23.0.0
Public Types | Static Public Member Functions | List of all members
dipki::Pbe Class Reference

Password-based encryption. More...

Public Types

enum class  PrfAlg
 PRF algorithm. More...
 

Static Public Member Functions

static bvec_t Kdf2 (int dklen, const std::string password, const bvec_t &salt, int count, PrfAlg prfalg=PrfAlg::Hmac_Sha1)
 Derive a key of any length from a password using the PBKDF2 algorithm from PKCS #5 v2.1. More...
 
static bvec_t Scrypt (int dklen, const std::string password, const bvec_t &salt, int N, int r, int p)
 Derive a key of any length from a password using the SCRYPT algorithm from RFC7914. More...
 

Detailed Description

Password-based encryption.

Member Enumeration Documentation

◆ PrfAlg

enum dipki::Pbe::PrfAlg
strong

PRF algorithm.

Enumerator
Hmac_Sha1 

HMAC-SHA-1 (default)

Hmac_Sha224 

HMAC-SHA-224.

Hmac_Sha256 

HMAC-SHA-256.

Hmac_Sha384 

HMAC-SHA-384.

Hmac_Sha512 

HMAC-SHA-512.

Member Function Documentation

◆ Kdf2()

static bvec_t dipki::Pbe::Kdf2 ( int  dklen,
const std::string  password,
const bvec_t salt,
int  count,
PrfAlg  prfalg = PrfAlg::Hmac_Sha1 
)
static

Derive a key of any length from a password using the PBKDF2 algorithm from PKCS #5 v2.1.

Parameters
dklenRequired length of key in bytes.
passwordPassword as a string.
saltSalt in byte array (to pass a value in hex use Cnv.FromHex).
countIteration count.
prfalgHMAC algorithm to use in PRF (default is HMAC-SHA-1).
Returns
Key in byte array.
dipki::bvec_t derived_key = dipki::Pbe::Kdf2(24, "password", dipki::Cnv::FromHex("78578E5A5D63CB06"), 2048);
cout << "derived_key=" << dipki::Cnv::ToHex(derived_key) << endl;
// derived_key=BFDE6BE94DF7E11DD409BCE20A0255EC327CB936FFE93643
static std::string ToHex(const bvec_t &bv)
Encodes an array of bytes as a hexadecimal-encoded string.
static bvec_t FromHex(const std::string &s)
Decodes a hexadecimal-encoded string as an array of bytes.
static bvec_t Kdf2(int dklen, const std::string password, const bvec_t &salt, int count, PrfAlg prfalg=PrfAlg::Hmac_Sha1)
Derive a key of any length from a password using the PBKDF2 algorithm from PKCS #5 v2....
std::vector< unsigned char > bvec_t
A vector of bytes (our typedef for a byte array)
Definition: dipki.hpp:79

◆ Scrypt()

static bvec_t dipki::Pbe::Scrypt ( int  dklen,
const std::string  password,
const bvec_t salt,
int  N,
int  r,
int  p 
)
static

Derive a key of any length from a password using the SCRYPT algorithm from RFC7914.

Parameters
dklenRequired length of key in bytes.
passwordPassword as a string.
saltSalt in byte array (to pass a value in hex use Cnv.FromHex).
NCPU/Memory cost parameter, a number greater than one and a power of 2..
rBlock size r.
pParallelization parameter p.
Returns
Key in byte array.
dipki::bvec_t derived_key = dipki::Pbe::Scrypt(64, "password", dipki::Cnv::FromHex("78578E5A5D63CB06"), 1024, 8, 16);
cout << "derived_key=" << dipki::Cnv::ToHex(derived_key) << endl;
// derived_key=FDBABE1C9D3472007856E7190D01E9FE7C6AD7CBC8237830E77376634B3731622EAF30D92E22A3886FF109279D9830DAC727AFB94A83EE6D8360CBDFA2CC0640
dipki::bvec_t derived_key = dipki::Pbe::Scrypt(64, "", dipki::Cnv::FromHex(""), 16, 1, 1);
cout << "derived_key=" << dipki::Cnv::ToHex(derived_key) << endl;
// derived_key=77D6576238657B203B19CA42C18A0497F16B4844E3074AE8DFDFFA3FEDE21442FCD0069DED0948F8326A753A0FC81F17E8D3E0FB2E0D3628CF35E20C38D18906
static bvec_t Scrypt(int dklen, const std::string password, const bvec_t &salt, int N, int r, int p)
Derive a key of any length from a password using the SCRYPT algorithm from RFC7914.
Copyright © 2004-24 D.I. Management Services Pty Limited t/a CryptoSys ABN 78 083 210 584 Australia. All rights reserved. <www.di-mgt.com.au> <www.cryptosys.net>. Generated on Mon Sep 23 2024 15:37:33 by Doxygen 1.9.1.