예제 #1
0
        /// <summary>
        /// Función encargada de encriptar los datos del usuario
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public ArrayList encryptOutlook(string password)
        {
            string    semilla     = "0uTl@k";
            string    marcaTiempo = "";
            ArrayList resultado   = new ArrayList();
            string    encriptado  = "";

            try
            {
                // do
                // {
                byte[]          iv     = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                IvParameterSpec ivspec = new IvParameterSpec(iv);
                marcaTiempo = (new SimpleDateFormat("ddMMyyyyHHmmss")).format(new Date());

                KeySpec       clave = new PBEKeySpec(marcaTiempo.ToCharArray(), Encoding.Default.GetBytes(semilla), 65536, 256);
                SecretKey     hash  = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(clave);
                SecretKeySpec key   = new SecretKeySpec(hash.getEncoded(), "AES");

                Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
                cipher.init(Cipher.ENCRYPT_MODE, key, ivspec);
                encriptado = Base64.getEncoder().encodeToString(cipher.doFinal(Encoding.UTF8.GetBytes(password)));
                resultado.add(encriptado);
                resultado.add(marcaTiempo);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Error en la encriptacion: " + e.ToString());
                resultado = new ArrayList();
            }
            return(resultado);
        }
예제 #2
0
            /// <exception cref="Sharpen.InvalidKeySpecException"></exception>
            /// <exception cref="Sharpen.NoSuchAlgorithmException"></exception>
            internal ObjectEncryptionV2(string algo, string key)
            {
                algorithmName = algo;
                PBEKeySpec s;

                s     = new PBEKeySpec(key.ToCharArray(), salt, ITERATION_COUNT, 32);
                skey  = SecretKeyFactory.GetInstance(algo).GenerateSecret(s);
                aspec = new PBEParameterSpec(salt, ITERATION_COUNT);
            }
        public void Add(string key, string value)
        {
            PBEKeySpec       keyspec = new PBEKeySpec(value.ToCharArray());
            SecretKeyFactory fk      = SecretKeyFactory.GetInstance("PBEWithMD5andDES");
            ISecretKey       mysec   = fk.GenerateSecret(keyspec);

            KeyStore.SecretKeyEntry entry = new KeyStore.SecretKeyEntry(mysec);

            keyStore.SetEntry(key, entry, Password);
            Save();
        }
예제 #4
0
        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());
        }
예제 #5
0
 public AESObfuscator(byte[] salt, string password)
 {
     try {
         SecretKeyFactory factory = SecretKeyFactory.GetInstance(KEYGEN_ALGORITHM);
         PBEKeySpec       keySpec =
             new PBEKeySpec(password.ToCharArray(), salt, 1024, 256);
         ISecretKey tmp    = factory.GenerateSecret(keySpec);
         ISecretKey secret = new SecretKeySpec(tmp.GetEncoded(), "AES");
         mEncryptor = Cipher.GetInstance(CIPHER_ALGORITHM);
         mEncryptor.Init(Cipher.EncryptMode, secret, new IvParameterSpec(IV));
         mDecryptor = Cipher.GetInstance(CIPHER_ALGORITHM);
         mDecryptor.Init(Cipher.DecryptMode, secret, new IvParameterSpec(IV));
     } catch (GeneralSecurityException e) {
         // This can't happen on a compatible Android device.
         throw new RuntimeException("Invalid environment", e);
     }
 }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AesObfuscator"/> class.
 /// The aes obfuscator.
 /// </summary>
 /// <param name="salt">
 /// an array of random bytes to use for each (un)obfuscation
 /// </param>
 /// <param name="applicationId">
 /// application identifier, e.g. the package name
 /// </param>
 /// <param name="deviceId">
 /// device identifier. Use as many sources as possible to
 /// create this unique identifier.
 /// </param>
 public AesObfuscator(byte[] salt, string applicationId, string deviceId)
 {
     try
     {
         SecretKeyFactory factory = SecretKeyFactory.GetInstance(KeygenAlgorithm);
         IKeySpec         keySpec = new PBEKeySpec((applicationId + deviceId).ToCharArray(), salt, 1024, 256);
         ISecretKey       tmp     = factory.GenerateSecret(keySpec);
         ISecretKey       secret  = new SecretKeySpec(tmp.GetEncoded(), "AES");
         this.encryptor = Cipher.GetInstance(CipherAlgorithm);
         this.encryptor.Init(CipherMode.EncryptMode, secret, new IvParameterSpec(Iv));
         this.decryptor = Cipher.GetInstance(CipherAlgorithm);
         this.decryptor.Init(CipherMode.DecryptMode, secret, new IvParameterSpec(Iv));
     }
     catch (GeneralSecurityException e)
     {
         // This can't happen on a compatible Android device.
         throw new RuntimeException("Invalid environment", e);
     }
 }
예제 #7
0
			/// <exception cref="Sharpen.InvalidKeySpecException"></exception>
			/// <exception cref="Sharpen.NoSuchAlgorithmException"></exception>
			internal ObjectEncryptionV2(string algo, string key)
			{
				algorithmName = algo;
				PBEKeySpec s;
				s = new PBEKeySpec(key.ToCharArray(), salt, ITERATION_COUNT, 32);
				skey = SecretKeyFactory.GetInstance(algo).GenerateSecret(s);
				aspec = new PBEParameterSpec(salt, ITERATION_COUNT);
			}