Exemple #1
0
        public static string Decrypt(this IdentityCoreKeyHandler handler, KeyDescriptor keyDescriptor, string encryptedData)
        {
            string EncryptionKey = keyDescriptor?.SecretKey?.Secret;
            var    signature     = keyDescriptor.KeySignature.Signature;
            var    lastKey       = EncryptionKey.Insert(EncryptionKey.Length, signature);

            encryptedData = encryptedData.Replace(" ", "+");
            byte[] cipherBytes = Convert.FromBase64String(encryptedData);
            using (Aes encryptor = Aes.Create())
            {
                Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(lastKey, new byte[] { 0x64, 0x76, 0x65, 0x64, 0x65, 0x76, 0x79, 0x88, 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65 });
                encryptor.Key = pdb.GetBytes(32);
                encryptor.IV  = pdb.GetBytes(16);
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(cipherBytes, 0, cipherBytes.Length);
                        cs.Close();
                    }
                    encryptedData = Encoding.Unicode.GetString(ms.ToArray());
                }
            }
            return(encryptedData);
        }
Exemple #2
0
        internal static string Encrypt(this IdentityCoreKeyHandler handler, KeyDescriptor keyDescriptor, string payload)
        {
            string EncryptionKey = keyDescriptor?.SecretKey?.Secret;
            var    signature     = keyDescriptor.KeySignature.Signature;
            var    lastKey       = EncryptionKey.Insert(EncryptionKey.Length, signature);

            byte[] clearBytes = Encoding.Unicode.GetBytes(payload);
            using (Aes encryptor = Aes.Create())
            {
                Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(lastKey, new byte[] { 0x64, 0x76, 0x65, 0x64, 0x65, 0x76, 0x79, 0x88, 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65 });
                encryptor.Key = pdb.GetBytes(32);
                encryptor.IV  = pdb.GetBytes(16);
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(clearBytes, 0, clearBytes.Length);
                        cs.Close();
                    }
                    payload = Convert.ToBase64String(ms.ToArray());
                }
            }
            return(payload);
        }
 public PrimeIdentityKey(KeyDescriptor keyDescriptor)
 {
     handler       = new IdentityCoreKeyHandler();
     KeyDescriptor = keyDescriptor;
 }