Exemplo n.º 1
0
        private static string HashPaste(Paste p)
        {
            HashAlgorithm algorithm          = SHA1.Create();
            var           computedHashString = Convert.ToBase64String(algorithm.ComputeHash(Encoding.UTF8.GetBytes(p.PasteData)));

            return(Regex.Replace(computedHashString, @"[^a-zA-Z0-9]", string.Empty));
        }
Exemplo n.º 2
0
        public static string StorePaste(Paste p)
        {
            if (string.IsNullOrEmpty(p.PasteData))
            {
                p.PasteData = "";
            }
            var pasteId          = HashPaste(p).Substring(0, 4);
            var directoryToWrite = GenerateDirectoryPathFromHash(pasteId);

            System.IO.File.WriteAllText(directoryToWrite + pasteId, p.PasteData);
            return(pasteId);
        }