Secret key that shows a different result? - encryption

A bit of a noob question here.
Is it possible to have an encrypted text that would show different results depending on the secret key used?
for example:
If I use secret key A the text would decrypt to show "123"
If I use secret key B the text would decrypt to show "456"
Is this possible?
Thanks

Related

One-click encryption of arbitrary regions in Emacs

I can use the epa-encrypt-region function to encrypt an arbitrary region of text. To do so, I perform
the following steps:
I am an evil user, so I use visual selection to mark the region that I want to encrypt.
I invoke the function using M-x. After doing this, I am greeted by a prompt with the following content:
Select recipients for encryption.
If no one is selected, symmetric encryption will be performed.
- ‘m’ to mark a key on the line
- ‘u’ to unmark a key on the line
[Cancel][OK]
u 8EF108635D200BC9 John Doe <john.doe#mail.com>
I move my cursor to the [OK] text and press enter. At this point, I am asked to enter a "Passphrase for symmetric encryption".
I enter a passphrase and press enter. At this point, the selected region gets encrypted. I can later decrypt the region by selecting it, invoking epa-decrypt-region and entering my passphrase.
How can I avoid having to press the [OK] button and to manually enter a password. I would like to be able to encrypt arbitrary regions by just performing two steps:
Select the region using visual selection
Invoke a function to encrypt the region with pre-defined passphrase.
Later, I want to be able to decrypt the region by selecting it, invoking a function and entering a
passphrase.
Does anyone know how I could achieve the above?

Is there a way to have Paw sort JSON response keys alphabetically when displayed?

Is there a way to have Paw sort JSON response key-value pairs by key alphabetically when displayed? This would make it easier to find entries at a glance without resorting to using a key path.
Paw has a "Sort Keys" option under Preferences -> Formatting, in the JSON section.

How to handle different-case usernames in Firebase?

I'm having an issue with Firebase DB involving case sensitive keys. For example: I create a "Username" key for every new user that registers. I'm validating this "Username" value through regex and also checking if the value entered already exists in the database (checking username availability). My issue is that I just realized Firebase assumes different sentence case of the same value is a different value.
For example:
"Username": john and
"Username": John are seen as two different/unique usernames
I was thinking taking the user's desired username input string and making it all caps (or all lowercase), creating uniformity in the database, but then it would kill the ability of having a mixed-case username. Is there a way to bypass this?
I had the same issue using firebase. The solution was create a new property with lowercase for "searchable" fields on my system. Also I remove the accents from words on this property.

Firebase insert with generated key

I have a root in firebase like in the I am trying to enable user to delete an item on list. But user can give up his decision. When user give up this decision, I want to insert the deleted item again in the database. But, I want to insert with old firebase generated key, because I am using firebase push keys. Is that a bad practice. How firebase generate these keys? Does it checks every key on db and generate a new one? Is that any possibility, that key marked as removed and generated later for another item? Sorry for the language. It has been hard to express.
EDITED: I want to use the old key because, I am getting the data with orderByKey. I dont want to lose order.
How firebase generate these keys? Does it checks every key on db and generate a new one?
Whenever you use push on a Database Reference, a new data node is generated with a unique key that includes the server timestamp. These keys look like -KiGh_31GA20KabpZBfa.
Because of the timestamp, you can be sure that the given key will be unique, without having to check the other keys inside your database.
Is that any possibility, that key marked as removed and generated later for another item?
No, it is not possible that two keys will collide, regardless of wether one has been removed or not.
But, I want to insert with old firebase generated key, because I am using firebase push keys. Is that a bad practice
Unfortunately, you can't generate the same key twice by just using push. So, it is not possible to delete a node with a given key and then use push to insert it again at the same path with the same key, because push would generate a different and unique key.
Instead of this, if ordering by key is that important to you, and there's a possibility that a deleted node can be reinserted then I would recommend you to do one of the following :-
Either save the key on the client side when it's deleted from the database, and use it when you need to reinsert.
Or , maybe, have a "deleted-keys" path in your database and save the deleted keys there. Of course, with this approach, you'd need to store additional information to identify the data that the key corresponds to.
It all really depends on your use case.
Calling push() will generate a key for you.
If instead you use child(), you can determine they key/path yourself.
ref.child("yourvalue").setValue("setting custom key when pushing new data to firebase database");
https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html

Where is password reset link stored in wordpress database

If you use Wordpress's built in password reset service it will go something like this:
Click forgot password
Enter your email or username
Receive a link in your email inbox
Click the link
Fill out form
That link you click, will look something like this:
http://yourdomain/wp-login.php?action=rp&key=vqwwSPzf6OK6bUv42XPk&login=natelough
If you try to change the &login to another name, it will reject you.
So, somewhere that 'key' is being stored in some way, and compared.
Where is it stored in the database?
I did an export of the database and searched the db for that string. It returned no results.
So what gives?
That key is generated by hashing a random string. You can see how this key is generated in the WordPress developer reference.
To answer your specific question, when a key is generated it is stored in the users table in the user_activation_key column. Only the most recently generated key is stored (invalidating previous reset keys). The key is also removed from the database once it has been used.
If you are looking to send these keys programmatically, you can generate them when you need them using get_password_reset_key(). That function accepts a WP_User object as its argument.
Depending on what you are trying to accomplish, there may be a more "best practices" way to do it than accessing that function directly.
The password is stored as a hash of the login name and password. You will find it in the users table under user_pass as an incomprehensible string. If the login name is changed, the entered password hashed with the login name will not match the string found in the database where the password was hashed with the original login name.

Resources