public void CreateKey() { // Removes key if it already exists, no change otherwise DeleteKey(); // Generate AES key var keyGenerator = KeyGenerator.GetInstance("AES"); keyGenerator.Init(KEY_SIZE); var secretKey = keyGenerator.GenerateKey(); // Push into the secureStorage _storageHelper.StoreItem <byte[]>(_keyAlias, secretKey.GetEncoded()); }
//public CertificateEncrypter(string certificateAlias) //{ // var certificate = _storageHelper.GetItem<byte[]>(certificateAlias); // var stream = new System.IO.MemoryStream(certificate, 0, certificate.Length); // _cert = CertificateFactory.GetInstance("X509").GenerateCertificate(stream); //} public CertificateEncrypter(string certificateAlias, byte[] serializedCertificate) { _storageHelper.StoreItem <byte[]>(certificateAlias, serializedCertificate); var stream = new System.IO.MemoryStream(serializedCertificate, 0, serializedCertificate.Length); var certificate = CertificateFactory.GetInstance("X509").GenerateCertificate(stream); _cert = certificate; }
public void CreateKey(string password, string userEmail) { // Remove key to overwrite, otherwise nothing DeleteKey(); // Make password based key with many iterations, a salt, and user-related value (email?) var spec = new PBEKeySpec((password + userEmail).ToCharArray(), SALT, ITERATIONS, KEY_SIZE); var keyGenerator = SecretKeyFactory.GetInstance("PBEWithHmacSHA256AndAES_256"); var key = keyGenerator.GenerateSecret(spec); _storageHelper.StoreItem <byte[]>(_keyAlias, key.GetEncoded()); }