I have encrypted email Address like
$this->load->library('encrypt');
$encoded = $this->encrypt->encode('user_email_address');
In codeigniter Model.
And after that when I tried to decode, it does not show the correct data.
$this->encrypt->decode('user_email_address');
It shows like
Jts¹+…Ru\¼A·¾Àp¤c’áµSîÆKÆ—l¿Ýƒ>ü«%c‚µ~SÔNÏŠÖä3; ñÑ
Please help me to solve this issue
Thanks in advance.
You can't use directly email to decode
Use it as
$this->load->library('encrypt');
$encodedEmail = $this->encrypt->encode('user_email_address');
$myEmail = $this->encrypt->decode($encodedEmail);
set encryption_key based on the algorithm used for encryption.
eg. for AES-128, encryption key must be 128 bits or 16 bytes (characters) long.
Or you can create key in your function itself before calling encode() function like:
$key = $this->encryption->create_key(16);
for more details : refer https://www.codeigniter.com/user_guide/libraries/encryption.html
Related
i would like to convert an image to Base64-encoded in esp32 cam . already i used method under detail like this :
ConvertBase64("D:/ok.jpg","D:/edcodedFolder");
but not working (edcodedFolder is empty)
maybe another/right way is using method under detail :
static String encode(const uint8_t * data, size_t length, bool doNewLines = true);
but i dont know how to use above method .
would you please help me?
finaly i found solution under detail that works fine
String encrypt = base64::encode(fb->buf, fb->len);
I am working with the STM8AF5286UDY and am trying to set up a CAN interface.
For programming, I use the standard peripheral library. At the moment, my CAN interface works fine. The only thing, which does not work, is filtering.
I use extended IDs and want to get all IDs from 0x18FEC100 to 0x18FEC999.
My code looks as follows:
/* CAN filter init */
CAN_FilterNumber = CAN_FilterNumber_0;
CAN_FilterActivation = ENABLE;
CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterScale = CAN_FilterScale_32Bit;
CAN_FilterID1=0x18FEC101;
CAN_FilterID2=0;
CAN_FilterID3=0;
CAN_FilterID4=0;
CAN_FilterIDMask1=0x1FFFF000;
CAN_FilterIDMask2=0;
CAN_FilterIDMask3=0;
CAN_FilterIDMask4=0;
CAN_FilterInit(CAN_FilterNumber, CAN_FilterActivation, CAN_FilterMode,
CAN_FilterScale,CAN_FilterID1, CAN_FilterID2, CAN_FilterID3,
CAN_FilterID4,CAN_FilterIDMask1, CAN_FilterIDMask2,
CAN_FilterIDMask3, CAN_FilterIDMask4);
I would appreciate any help! Thank you!
EDIT: In my initial code, I forgot to include IDE and RTR at addressing. Also, in the library, each address and mask is an 8-bit value. Therefore, I have changed my code to the following:
/* CAN filter init */
CAN_FilterNumber = CAN_FilterNumber_2;
CAN_FilterActivation = ENABLE;
CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterScale = CAN_FilterScale_32Bit;
CAN_FilterID1=0xc7;
CAN_FilterID2=0xed;
CAN_FilterID3=0x02;
CAN_FilterID4=0x02;
CAN_FilterIDMask1=0xFF;
CAN_FilterIDMask2=0xE7;
CAN_FilterIDMask3=0xE0;
CAN_FilterIDMask4=0x00;
CAN_FilterInit(CAN_FilterNumber, CAN_FilterActivation, CAN_FilterMode,
CAN_FilterScale,CAN_FilterID1, CAN_FilterID2, CAN_FilterID3,
CAN_FilterID4,CAN_FilterIDMask1, CAN_FilterIDMask2,
CAN_FilterIDMask3, CAN_FilterIDMask4);
This filter works for the first 16-bit, so at using 0x18FEC101 it filters the 0x18FE. Somehow, it does not work for the other 16-bit.
In the library, the following code is used for writing the addresses and masks in the filter bank at 32-bit:
else if (CAN_FilterScale == CAN_FilterScale_32Bit)
{
CAN->Page.Filter.FR01 = CAN_FilterID1;
CAN->Page.Filter.FR02 = CAN_FilterID2;
CAN->Page.Filter.FR03 = CAN_FilterID3;
CAN->Page.Filter.FR04 = CAN_FilterID4;
CAN->Page.Filter.FR05 = CAN_FilterIDMask1;
CAN->Page.Filter.FR06 = CAN_FilterIDMask2;
CAN->Page.Filter.FR07 = CAN_FilterIDMask3;
CAN->Page.Filter.FR08 = CAN_FilterIDMask4;
}
Are there any ideas, what my mistake might be?
Thanks!
Mask filtering works bitwise. So you can't create a filter to accept values between 0x18FEC100 - 0x18FEC999. You need to think binary.
In the filter mask registers, 1 means "must match" and 0 means "don't care".
ID = 0x18FEC101 and Mask = 0x1FFFF000 means that it will accept values between 0x18FEC000 - 0x18FECFFF as the filter won't care the least significant 12 bits.
However, the process is further complicated by the bit arrangement of the hardware registers. Be aware that RTR & IDE bits are also included in the filter registers. I don't know if the standard peripheral library handles this but probably not. You probably need to manually arrange the bits to determine the correct register values. In the reference manual (RM0016), refer to Figure 148.
The code I posted (edited version) works now.
Turns out I had a problem calculating the addresses by hand.
Thank you #Tagli.
I'm using Hash::make to hash the customer id in my laravel api controller. But when I return the Hashed customer id I get wrong characters. Here is my code:
$key=Hash::make($input['key']);
$createnewkey=DB::table('customers')->where('custid', $input['custid'])
->update(array("key"=>$key));
return ["STATUS"=>1, "KEY"->$key];
I got for example : Av$#wqe#!3aferty10/2YyAU .... and that's saved in the database.
But the request response is : Av$#wqe#!3aferty10/\2YyAU the \ or / is always replaced with /\ that will corrupt my hash code compare
Laravel Hash use the password_hash function of the PHP. This function will generate the base64 encoded string. Which has the / in its character list. So if you will pass that in the URL your URL will get corrupted.
Instead, you can use hashids to encrypt the keys which are passed in URls.
This is the hashids port for laravel : https://github.com/vinkla/laravel-hashids
I am trying to do this route trick:
$route['cp/roles/:num'] = "cp/roles/index/:num";
but it doesn't work :(
please help me!!
advanced thanks .
According to the documentation on URI Routing:
$route['product/(:num)'] = "catalog/product_lookup_by_id/$1";
“A URL with "product" as the first segment, and a number in the second will be remapped to the "catalog" class and the "product_lookup_by_id" method passing in the match as a variable to the function.”
So, for your particular instance, you would do the following:
$route['cp/roles/(:num)'] = "cp/roles/index/$1";
You could try
$route['cp/roles/:num'] = "cp/roles";
and then instead of passing a variable in your function you use
$this->uri->segment(3);
or the number that correspond to the segment.
I'm trying to get as3crypto to play nice with either Gibberish or EzCrypto in AES-128 mode.
No matter what combination of settings I use I simply cannot get one to decrypt the other, and usually get a "bad decrypt" message in ruby. Each contained environment can decrypt data it encrypted itself but one cannot seem to decrypt the other.
Has anyone been able to get the two to work together?
Here's one of the variations I tried:
On the Actionscript side, using as3crypto:
//define the encryption key
var key:ByteArray = Hex.toArray("password");
//put plaintext into a bytearray
var plainText:ByteArray = Hex.toArray(Hex.fromString("this is a secret!"));
//set the encryption key
var aes:AESKey = new AESKey(key);
//encrypt the text
aes.encrypt( plainText );
trace(Base64.encode(Hex.fromArray(plainText)));
//encrypted value is N2QwZmI0YWQ4NzhmNDNhYjYzM2QxMTAwNGYzNDI1ZGUyMQ==
And on the ruby side, using gibberish:
// also tried the default size (256)
cipher = Gibberish::AES.new("password",128)
// raises the following exception: OpenSSL::Cipher::CipherError: wrong final block length
cipher.dec("N2QwZmI0YWQ4NzhmNDNhYjYzM2QxMTAwNGYzNDI1ZGUyMQ==")
I've tried all sort of different approaches, all yielding either the above exception or "bad encrypt"
Finally figured it out myself. The thing is both Gibberish and EzCrypto do not seem to provide a way to specify an IV, which is needed when using aes-cbc. The trick is to extract the iv from the first 16 bytes of the encrypted data as3crypto produces.
Here's the as3 code, which also changed a little:
// there are other ways to create the key, but this works well
var key:ByteArray = new ByteArray();
key.writeUTFBytes(MD5.encrypt("password"));
// encrypt the data. simple-aes-cbc is equiv. to aes-256-cbc in openssl/ruby, if your key is
// long enough (an MD5 is 32 bytes long)
var data:ByteArray = Hex.toArray(Hex.fromString("secret"));
var mode:ICipher= Crypto.getCipher("simple-aes-cbc", key) ;
mode.encrypt(data);
// the value here is base64, 32 bytes long. the first 16 bytes are the IV, needed to decrypt
// the data in ruby
// e.g: sEFOIF57LVGC+HMEI9EMTpcJdcu4J3qJm0PDdHE/OSY=
trace(Base64.encodeByteArray(data));
The ruby part uses a gem called encryptor to supply the iv.
you can also use OpenSSL directly, it's pretty straight forward:
key = Digest::MD5.hexdigest("password")
// decode the base64 encoded data back to binary:
encrypted_data = Base64.decode64("sEFOIF57LVGC+HMEI9EMTpcJdcu4J3qJm0PDdHE/OSY=")
// the tricky part: extract the IV from the decoded data
iv = encrypted_data.slice!(0,16)
// decrypt!
Encryptor.decrypt(encrypted_data,:key=>key,:iv=>iv)
// should output "secret"