I'm new to this encryption thing, so i'm not realy sure how to format my question.
Anyways i'm using framework called kohana
and for encryption it uses three things:
key
, cipher
, mode
so my problem is that when it encodes some string sometimes i get /
in encryption like this fclzSev6DVfOk2Z/BSSi4dRYFn4t
and i don't want that so my guess is that i should change mode
which right now is MCRYPT_MODE_NOFB
so if i'm right what mode do i have to use?
As Francis Avila notes, the encrypted output seems to be Base64-encoded, and so may contain slashes and plus signs (and possibly equals signs at the end) in addition to letters and numbers.
You can safely replace those signs with something else, as long as you remember to change them back before decoding. The PHP strtr()
function is handy for this. For example, here's how to convert a string from normal Base64 to the RFC 4648 URL-safe Base64 variant and back:
$url_safe_base64 = strtr( $base64_string, "+/", "-_" );
$base64_string = strtr( $url_safe_base64, "-_", "+/" );
mode
has absolutely nothing to do with whether the generated output has slashes, but specifies what mode of encryption mcrypt
should use. If you don't know what it's for use the default.
The reason there are slashes is that Kohana's encode()
method will encode the binary output from the encryption in base64, which may contain slashes.
You can str_replace()
the slashes with something else, but this will probably create more problems and headaches than it solves.