Mam dwie różne funkcje szyfrujące i deszyfrujące:
Wykorzystanie mcrypt:
function encryptnow($thecipher, $thekey, $themsg)
{
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($thecipher), MCRYPT_RAND);
mcrypt_generic_init($thecipher, $thekey, $iv);
$encrypted_text = mcrypt_generic($thecipher, $themsg);
mcrypt_generic_deinit($thecipher);
mcrypt_module_close($thecipher);
return $encrypted_text;
}
function decryptnow($thecipher, $thekey, $thencrypted){
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($thecipher), MCRYPT_RAND);
mcrypt_generic_init($thecipher, $thekey, $iv);
$decrypted_text = mdecrypt_generic($thecipher, $thencrypted);
mcrypt_generic_deinit($thecipher);
mcrypt_module_close($thecipher);
return $decrypted_text;
}
function startEncrytpion($choice, $mykey, $msg){
if ($choice == '1'){
$cipher = mcrypt_module_open (MCRYPT_DES, '', 'ecb', '');
//algorithmdetails($cipher);
return encryptnow($cipher, $mykey, $msg);
}elseif ($choice == '2'){
$cipher = mcrypt_module_open (MCRYPT_3DES, '', 'ecb', '');
//algorithmdetails($cipher);
return encryptnow($cipher, $mykey, $msg);
}elseif ($choice == '3'){
$cipher = mcrypt_module_open (MCRYPT_RIJNDAEL_128, '', 'ecb', '');
//algorithmdetails($cipher);
return encryptnow($cipher, $mykey, $msg);
}elseif ($choice == '4'){
$cipher = mcrypt_module_open (MCRYPT_GOST, '', 'ecb', '');
//algorithmdetails($cipher);
return encryptnow($cipher, $mykey, $msg);
}
}
function startDecrytpion($choice, $mykey, $msg){
if ($choice == '1'){
$cipher = mcrypt_module_open (MCRYPT_DES, '', 'ecb', '');
//algorithmdetails($cipher);
return decryptnow($cipher, $mykey, $msg);
}elseif ($choice == '2'){
$cipher = mcrypt_module_open (MCRYPT_3DES, '', 'ecb', '');
//algorithmdetails($cipher);
return decryptnow($cipher, $mykey, $msg);
}elseif ($choice == '3'){
$cipher = mcrypt_module_open (MCRYPT_RIJNDAEL_128, '', 'ecb', '');
//algorithmdetails($cipher);
return decryptnow($cipher, $mykey, $msg);
}elseif ($choice == '4'){
$cipher = mcrypt_module_open (MCRYPT_GOST, '', 'ecb', '');
//algorithmdetails($cipher);
return decryptnow($cipher, $mykey, $msg);
}
}
i takie proste szyfrowanie:
function Encrypt($string, $key){
$result = '';
for($i=1; $i<=strlen($string); $i++){ $char = substr($string, $i-1
, 1
); $char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return $result;
}
function Decrypt($string, $key){
$result = '';
for($i=1; $i<=strlen($string); $i++){ $char = substr($string, $i-1
, 1
); $char = chr(ord($char)-ord($keychar));
$result.=$char;
}
return $result;
}
Próbuję zaszyfrować tekst i wpisać go do bazy MSSQL do kolumny o typie "text"
Jednak po wyciągnięciu tych danych z bazy i odszyfrowaniu uzyskuję krzaczki.
Wiem że rozwiązania takie działają z bazą MySql. Czy zna ktoś sposób jak zapisać zaszyfrowane dane do bazy MSSQL tak
aby po wyciągnięciu ich i odszyfrowaniu uzyskać to samo co przed szyfrowaniem i zapisaniem? Niestety nie mogę korzystać
z bazy MySql.