src/Webtrees/Functions/Functions.php
public static function decryptFromSafeBase64($encrypted){
		$encrypted = str_replace('-', '+', $encrypted);
		$encrypted = str_replace('_', '/', $encrypted);
		$encrypted = str_replace('*', '=', $encrypted);
		$encrypted = base64_decode($encrypted);
		if($encrypted === false)
			throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.');
		
		if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES))
		    throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.');

	    $nonce = mb_substr($encrypted, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
	    $ciphertext = mb_substr($encrypted, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');
        
        $decrypted = sodium_crypto_secretbox_open($ciphertext, $nonce, self::getBase64EncryptionKey());
		
        if($decrypted === false) {
            throw new \InvalidArgumentException('The message has been tampered with in transit.');
        }
        
        //sodium_memzero($encrypted);   // Requires PHP 7.2
        
        return $decrypted;
	}
public static function decryptFromSafeBase64($encrypted){
		$encrypted = str_replace('-', '+', $encrypted);
		$encrypted = str_replace('_', '/', $encrypted);
		$encrypted = str_replace('*', '=', $encrypted);
		$encrypted = base64_decode($encrypted);
		if($encrypted === false)
			throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.');
		
		if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES))
		    throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.');

	    $nonce = mb_substr($encrypted, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
	    $ciphertext = mb_substr($encrypted, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');
        
        $decrypted = sodium_crypto_secretbox_open($ciphertext, $nonce, self::getBase64EncryptionKey());
		
        if($decrypted === false) {
            throw new \InvalidArgumentException('The message has been tampered with in transit.');
        }
        
        //sodium_memzero($encrypted);   // Requires PHP 7.2
        
        return $decrypted;
	}
public static function decryptFromSafeBase64 ( $ encrypted ) { $ encrypted = str_replace ( '-' , '+' , $ encrypted ) ; $ encrypted = str_replace ( '_' , '/' , $ encrypted ) ; $ encrypted = str_replace ( '*' , '=' , $ encrypted ) ; $ encrypted = base64_decode ( $ encrypted ) ; if ( $ encrypted === false ) throw new \ InvalidArgumentException ( 'The encrypted value is not in correct base64 format.' ) ; if ( mb_strlen ( $ encrypted , '8bit' ) < ( SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES ) ) throw new \ InvalidArgumentException ( 'The encrypted value does not contain enough characters for the key.' ) ; $ nonce = mb_substr ( $ encrypted , 0 , SODIUM_CRYPTO_SECRETBOX_NONCEBYTES , '8bit' ) ; $ ciphertext = mb_substr ( $ encrypted , SODIUM_CRYPTO_SECRETBOX_NONCEBYTES , null , '8bit' ) ; $ decrypted = sodium_crypto_secretbox_open ( $ ciphertext , $ nonce , self :: getBase64EncryptionKey ( ) ) ; if ( $ decrypted === false ) { throw new \ InvalidArgumentException ( 'The message has been tampered with in transit.' ) ; } //sodium_memzero($encrypted);   // Requires PHP 7.2 return $ decrypted ; }
Decode and encrypt a text from base64 compatible with URL use

@param string $encrypted Text to decrypt
@return string Decrypted text
Decode and encrypt a text from base64 compatible with URL use