private bool DecryptAssetBase(AssetBase x) { // Check it's encrypted first. if (!x.Description.Contains("ENCASS")) { return(true); } // ENCASS:ALG:AKA:SALT:Description // 0 1 2 3 4 string[] splitchars = new string[1]; splitchars[0] = "#:~:#"; string[] meta = x.Description.Split(splitchars, StringSplitOptions.None); if (meta.Length < 5) { m_log.Warn("[ENCASSETS] Recieved Encrypted Asset, but header is corrupt"); return(false); } // Check if we have a matching key if (m_keyfiles.ContainsKey(meta[2])) { RjinKeyfile deckey = m_keyfiles[meta[2]]; x.Description = meta[4]; switch (meta[1]) { case "OPENSIM_AES_AF1": x.Data = UtilRijndael.Decrypt(x.Data, deckey.Secret, meta[3], "SHA1", 2, deckey.IVBytes, deckey.Keysize); // Decrypted Successfully return(true); default: m_log.Warn( "[ENCASSETS] Recieved Encrypted Asset, but we dont know how to decrypt '" + meta[1] + "'."); // We dont understand this encryption scheme return(false); } } m_log.Warn("[ENCASSETS] Recieved Encrypted Asset, but we do not have the decryption key."); return(false); }
private static void EncryptAssetBase(AssetBase x, RjinKeyfile file) { // Make a salt RNGCryptoServiceProvider RandomGen = new RNGCryptoServiceProvider(); byte[] rand = new byte[32]; RandomGen.GetBytes(rand); string salt = Convert.ToBase64String(rand); x.Data = UtilRijndael.Encrypt(x.Data, file.Secret, salt, "SHA1", 2, file.IVBytes, file.Keysize); x.Description = String.Format("ENCASS#:~:#{0}#:~:#{1}#:~:#{2}#:~:#{3}", "OPENSIM_AES_AF1", file.AlsoKnownAs, salt, x.Description); }