Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
crypto_box_secretkey example
if
(
!
is_callable
(
'sodium_crypto_box_secretkey'
)
)
{
/** * @see ParagonIE_Sodium_Compat::crypto_box_secretkey() * @param string $key_pair * @return string * @throws SodiumException * @throws TypeError */
function
sodium_crypto_box_secretkey
(
$key_pair
)
{
return
ParagonIE_Sodium_Compat::
crypto_box_secretkey
(
$key_pair
)
;
}
}
if
(
!
is_callable
(
'sodium_crypto_box_seed_keypair'
)
)
{
/** * @see ParagonIE_Sodium_Compat::crypto_box_seed_keypair() * @param string $seed * @return string * @throws SodiumException * @throws TypeError */
function
sodium_crypto_box_seed_keypair
(
$seed
)
{
if
(
!
is_callable
(
'\\Sodium\\crypto_box_secretkey'
)
)
{
/** * @see ParagonIE_Sodium_Compat::crypto_box_secretkey() * @param string $keypair * @return string * @throws \SodiumException * @throws \TypeError */
function
crypto_box_secretkey
(
$keypair
)
{
return
ParagonIE_Sodium_Compat::
crypto_box_secretkey
(
$keypair
)
;
}
}
if
(
!
is_callable
(
'\\Sodium\\crypto_generichash'
)
)
{
/** * @see ParagonIE_Sodium_Compat::crypto_generichash() * @param string $message * @param string|null $key * @param int $outLen * @return string * @throws \SodiumException * @throws \TypeError */
$ofp
=
fopen
(
$outputFile
, 'wb'
)
;
if
(
!
is_resource
(
$ofp
)
)
{
fclose
(
$ifp
)
;
throw
new
SodiumException
(
'Could not open output file for writing'
)
;
}
/** @var string $ephKeypair */
$ephKeypair
= ParagonIE_Sodium_Compat::
crypto_box_keypair
(
)
;
/** @var string $msgKeypair */
$msgKeypair
= ParagonIE_Sodium_Compat::
crypto_box_keypair_from_secretkey_and_publickey
(
ParagonIE_Sodium_Compat::
crypto_box_secretkey
(
$ephKeypair
)
,
$publicKey
)
;
/** @var string $ephemeralPK */
$ephemeralPK
= ParagonIE_Sodium_Compat::
crypto_box_publickey
(
$ephKeypair
)
;
/** @var string $nonce */
$nonce
= ParagonIE_Sodium_Compat::
crypto_generichash
(
$ephemeralPK
.
$publicKey
,
'',
24
)
;