I wanted to save the public and private keys obtained by RSA to Userdefaults. but every time it enters the app, it generates a new key and rewrites it to Userdefaults. but what should I do so that it doesn't save to userdefaults again and again ?
Related
I need to store two strings as one secret value in key vault.
account="aa" key="1254"
But all SetSecretAsync syntaxes accept one string as secret value..
I am not sure if tags can be revelevant here.
Please help!
You could use Newtonsoft Json.NET to serialize an object to a JSON string:
var account = new Account { account = "aa", key = "1254" };
string json = JsonConvert.SerializeObject(account);
This string will contain this:
{"account":"aa","key":"1254"}
which can be stored as the secret.
When you subsequently load the secret, you could then use Json.NET to deserialize the string back into an object:
var account = JsonConvert.DeserializeObject<Account>(json);
As for tags, you could use a tag to indicate what's contained within the secret, and this could be useful if you'll be storing different object types within secrets (not just accounts, for instance). Tags are just key-value pairs, so you could create a tag like so:
secret.Tags = new Dictionary<string, string>
{
["Type"] = "Account"
};
But if you're always going to be storing accounts, then this isn't strictly necessary.
A client of mine came with the following demand:
Add the option to upload a file to the server
Save the file id as a guid in database
I followed this answer- so the file upload is working(to a specific location on the server)
http://stackoverflow.com/questions/5193842/file-upload-asp-net-mvc-3-0
What i don't familiar with is his second demand:
Save the file id as a guid in database
What does it mean?
Why does the file need a guid id in the database?
What should I do in extra to the post I linked to?(security check, extension check?)
guid = globaly unique identifier.
Why does a file need a guid in database ? well because its your client's requirement its not required by the database.
And finally how to do it? is simple when you will be saving a filename to database generate a guid and save it to the database you can generate a guid like this Guid id = Guid.NewGuid(); and you can create a separate column in the database for saving file's guids.
I have created a pair of private/public keys using SecKeyGeneratePair. I am successfully able to use the public key to encode and private key to decode. However, I need to save the public key and pass it to another user. That user then needs to create a SecKeyRef object using that public key to encode a text and send it back. I can then use the private key to decode it.
This all works within a single application where the public key and private keys are already loaded in SecKeyRef. I have used the Apple recommended code to get publicKeyBits. But, no matter which I call I have tried, I haven't been successful in creating a SecKeyRef to do my encoding/decoding.
My questions are:
How do I save my public key and how do I pass it on?
How do I create a new SecKeyRef object using that public key in a new instance of a client?
I know how to save documents to the RavenDB but i'm trying to look in to how I can save a User object:
public class User
{
public string Username {get;set;}
public string Password {get;set;}
public string Email {get;set;}
}
Sure, I can save an object of User but, what about Password encryption? And is there a "proper" or a different way of saving a User object? Saving and Retrieving a User object is my whole goal.
Any help is highly appreciated.
Password encryption you'd have to implement yourself. See an example here:
https://github.com/synhershko/NSemble/blob/master/NSemble.Web/Modules/Welcome/WelcomeModule.cs
https://github.com/synhershko/NSemble/blob/master/NSemble.Core/Nancy/NSembleUserAuthentication.cs
The User object is not different than any other object in your system.
I have a simple web app that has a login page, the front end domain has a simple model with:
string username {get;set;}
string password {get;set;}
However it is encrypted with sha256 before it is sent over to the data domain object, originally the data domain was:
string username {get;set;}
string password {get;set;}
So I would take the password from the ui, encrypt it then using the Encoding.GetString() method, get back a string for persisting. However when I try to persist the data it just seems to give an exception, which I believe to be down to the characters in the string not being valid.
After looking around some people have recommended storing it as a varbinary(32) and using a byte[] password {get;set;} within the data layer, however I couldn't get Nhibernate to map it correctly.
So can anyone tell me the best practise on storing hashed passwords with Nhibernate and SqlServer or MySql. (The app supports both dbs)
You shouldn't use Encoding.GetString() on a SHA value since it will produce text that may not store correctly, or worse, give an exception. Rather use something like Convert.ToBase64String.