Hello friends
I use the following 2 functions in php language for Encryption HMACSHA256
Can you help me write it in B4A from PHP?
??????
Git link
I use the following 2 functions in php language for Encryption HMACSHA256
Can you help me write it in B4A from PHP?
PHP:
$key = '12345';
$raw = 'testttttttttttttttttttttttttttttttttttttttt';
$meta = [ 'name' => 'test-name', 'email' => '[email protected]' ];
PHP:
function encrypt( $key, $plaintext, $meta = '' ) {
// Generate valid key
$key = hash_pbkdf2( 'sha256', $key, '', 10000, 0, true );
// Serialize metadata
$meta = serialize($meta);
// Derive two subkeys from the original key
$mac_key = hash_hmac( 'sha256', 'mac', $key, true );
$enc_key = hash_hmac( 'sha256', 'enc', $key, true );
$enc_key = substr( $enc_key, 0, 32 );
// Derive a "synthetic IV" from the nonce, plaintext and metadata
$temp = $nonce = ( 16 > 0 ? mcrypt_create_iv( 16 ) : "" );
$temp .= hash_hmac( 'sha256', $plaintext, $mac_key, true );
$temp .= hash_hmac( 'sha256', $meta, $mac_key, true );
$mac = hash_hmac( 'sha256', $temp, $mac_key, true );
$siv = substr( $mac, 0, 16 );
// Encrypt the message
$enc = mcrypt_encrypt( 'rijndael-128', $enc_key, $plaintext, 'ctr', $siv );
return base64_encode( $siv . $nonce . $enc );
}
??????
Git link