"; print_r($Field); echo ""; # $IV_C...">

Divide the string by X, then by Y

I have the following code:

$Field = $FW->Encrypt("Test"); echo "<pre>"; print_r($Field); echo "</pre>"; # $IV_Count = strlen($Field['IV']); # $Key_Count = strlen($Field['Key']); # $Cipher_Count = strlen($Field['CipheredText']); foreach ($Field AS $Keys => $Values){ echo $Keys."Count = ".strlen($Values)."<br><br>"; } 

The output looks like this:

 Array ( [CipheredText] => x2nelnArnS1e2MTjOrq+wd9BxT6Ouxksz67yVdynKGI= [IV] => 16 [Key] => III#TcTf‡eB12T ) CipheredTextCount = 44 IVCount = 2 KeyCount = 16 

IV / KeyCount always returns the same value regardless of input. But CipheredTextCount changes depending on the input. For instance:

  $Field = $FW->Encrypt("This is a longer string"); 

The foreach returns:

CipheredTextCount = 64

IVCount = 2

KeyCount = 16

and now for my question. Let's take the first example with TextCount of 44

How can I break a line after implode("",$Field); to display as source array? an example would be:

  echo implode("",$Field); 

What outputs:

 ijGglH/vysf52J5aoTaDVHy4oavEBK4mZTrAL3lZMTI=16III#TcTf‡eB12T 

Based on strlen results?

You can store the counter of the first $Cipher_Count in the database for reference


My current setup involves saving the key and IV in a separate column away from the encrypted text string. I need this to be contained in one field, and the script processes the necessary information to do the following:

Get a long string> Split the string into the original array> Push array to another function> decrypt> return decoded string.

+4
source share
2 answers

Why not use serialize instead? Then, when you get the data from the database, you can use unserialize to restore it to the array.

+1
source
 $Combined_Field = implode("",$Field); echo $str1 = substr($Combined_Field, 0, $Cipher_Count)."<br><br>"; echo $str2 = substr($Combined_Field,$Cipher_Count,$IV_Count)."<br><br>"; echo $str3 = substr($Combined_Field, $IV_Count+$Cipher_Count,$Key_Count); 

Or use the function:

 function Cipher_Split($Cipher, $Cipher_Count, $KeyCount, $IVCount){ return array( "Ciphered Text" => substr($Cipher,0,$Cipher_Count), "IV" => substr($Cipher,$Cipher_Count,$IVCount), "Key" => substr($Cipher,$IVCount+$Cipher_Count,$KeyCount) ); } 
0
source

Source: https://habr.com/ru/post/1485510/


All Articles