source: trunk/PKCS1/Library/Hashfunction.cs @ 1650

Last change on this file since 1650 was 1650, checked in by schomburg, 11 years ago

initial commit of PKCS1 Plugin

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Org.BouncyCastle.Crypto;
6using Org.BouncyCastle.Security;
7
8namespace PKCS1.Library
9{
10    class Hashfunction
11    {
12        private static IDigest hashFunctionDigest = DigestUtilities.GetDigest(HashFunctionHandler.SHA1.diplayName); // default SHA1
13
14        public static byte[] generateHashDigest(string input, HashFunctionIdent hashIdent)
15        {
16            return generateHashDigest(Encoding.ASCII.GetBytes(input), hashIdent);
17        }
18
19        public static byte[] generateHashDigest(byte[] input, HashFunctionIdent hashIdent)
20        {   
21            hashFunctionDigest = DigestUtilities.GetDigest(hashIdent.diplayName);
22            byte[] hashDigest = new byte[hashFunctionDigest.GetDigestSize()];
23            hashFunctionDigest.BlockUpdate(input, 0, input.Length);
24            hashFunctionDigest.DoFinal(hashDigest, 0);           
25
26            return hashDigest;
27        }
28
29        // gibt länge in bytes zurück!
30        public static int getDigestSize()
31        {
32            return hashFunctionDigest.GetDigestSize();
33        }
34
35        public static string getAlgorithmName()
36        {
37            return hashFunctionDigest.AlgorithmName;
38        }
39    }
40}
Note: See TracBrowser for help on using the repository browser.