Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Question attribute "Encrypted" is used to enable data encryption

  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 1 month ago #251168 by MikhailGorbunov
Please help us help you and fill where relevant:
Your LimeSurvey version: [5.6.40]
Own server or LimeSurvey hosting: own

==================
How to show respondent answers from database in external .php file if question attribute "Encrypted" is used to enable data encryption?
select id, submitdate, AES_DECRYPT(1X2X3SQ001, 'key'); returns NULL

Please Log in to join the conversation.

  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 1 month ago #251169 by MikhailGorbunov
Tryed

require_once '/path/vendor/autoload.php'; // Adjust the path to the autoload.php file

use LimeSurvey\Survey\Repository as SurveyRepository;
use LimeSurvey\Token\Provider as TokenProvider;

$surveyRepository = new SurveyRepository();
$tokenProvider = new TokenProvider();

$surveyId = 123;
$tokens = $tokenProvider->getTokens($survey);

foreach ($tokens as $token) {
    $participantToken = $token->getToken();
    $responseData = $tokenProvider->getResponseData($survey, $participantToken);
 
    // Display the participant's token
    echo "Token: $participantToken <br>";
 
    // Display the question answers
    foreach ($responseData as $questionId => $questionData) {
        echo "Question ID: $questionId <br>";
        
        foreach ($questionData as $subQuestionId => $answer) {
            echo "Sub-Question ID: $subQuestionId <br>";
            echo "Answer: $answer <br>";
        }
    }
 
    echo "<br>";
}
with LimeSurvey\Survey\Repository not found error.

Please Log in to join the conversation.

  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 1 month ago - 1 year 1 month ago #251171 by MikhailGorbunov
Code:
[code][code]while ($row=mysqli_fetch_array($result )){
sodium_crypto_secretbox_open($row['111111X1X1SQ001'],$nonce,$key)
}
[/code]
[/code]
Code:
with nonce and key from config.php trows

PHP Fatal error: Uncaught SodiumException: sodium_crypto_secretbox_open(): Argument #2 ($nonce) must be SODIUM_CRYPTO_SECRETBOX_NONCEBYTES bytes long in
Last edit: 1 year 1 month ago by MikhailGorbunov.

Please Log in to join the conversation.

More
11 months 1 week ago #253633 by OpenStudio
Did you manage to solve?
I am also having the same necessity/issue!

Please Log in to join the conversation.

  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 months 1 week ago - 11 months 1 week ago #253652 by MikhailGorbunov

Did you manage to solve?
I am also having the same necessity/issue!

 
Hello.
No I don`t still trying.
I know uncrypted data is shown in admin menu.
You can track issue in stackoverflow.com
Last edit: 11 months 1 week ago by MikhailGorbunov.
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
11 months 1 week ago #253666 by DenisChenu
Moving it to development section

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
11 months 1 week ago #253668 by DenisChenu

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 months 1 week ago - 11 months 1 week ago #253669 by MikhailGorbunov

Some code
github.com/LimeSurvey/LimeSurvey/blob/41...re/LSSodium.php#L135

Maybe need base64_decode ?
Error in nonce or key format. You can see at line 139 they are not decoded.
Code:
$this->sEncryptionNonce, $this->sEncryptionSecretBoxKey

But i think they encoded in Limesurvey config file and one should decrypt nonce and key before use.

Main mystery is how to decrypt nonce and key from config file to solve Argument #2 ($nonce) must be SODIUM_CRYPTO_SECRETBOX_NONCEBYTES bytes long in problem in sodium_crypto_secretbox_open() function.
 
Last edit: 11 months 1 week ago by MikhailGorbunov.

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
11 months 1 week ago #253670 by DenisChenu

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 months 1 week ago - 11 months 1 week ago #253698 by MikhailGorbunov
Tryed sodium_hex2bin() function on them like this.
Code:
sodium_crypto_secretbox_open($row['111111X1X1SQ001'],sodium_hex2bin('nonce'),sodium_hex2bin('key'))
Without any error, but no decryption, clean error.log in apache, status 200 in access log, but just blank variable without data :( 
applyed base64_decode() on
Code:
sodium_crypto_secretbox_open() output with same effect.
Last edit: 11 months 1 week ago by MikhailGorbunov.

Please Log in to join the conversation.

  • MikhailGorbunov
  • MikhailGorbunov's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
11 months 1 week ago #253700 by MikhailGorbunov
Code:
sodium_crypto_secretbox_open(base64_decode($row['111111X1X1SQ001']),sodium_hex2bin('$nonce'),sodium_hex2bin('$key'))

works fine. Feel free to use this solution on external .php data output with nonce and key from secure.php in config directory.
The following user(s) said Thank You: DenisChenu, OpenStudio

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
11 months 1 week ago #253701 by DenisChenu
Great ! You got it !!

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose