source: trunk/CrypPlugins/PKCS1/Library/RsaSig.cs

Last change on this file was 8109, checked in by kopal, 3 years ago
  • removed all unused references from all source code files
File size: 1.9 KB
Line 
1using System;
2using Org.BouncyCastle.Crypto;
3using Org.BouncyCastle.Crypto.Encodings;
4using Org.BouncyCastle.Crypto.Engines;
5using Org.BouncyCastle.Utilities.Encoders;
6
7namespace PKCS1.Library
8{
9    public class RsaSig : Signature
10    {
11        #region encrypted PKCS1 Signature
12
13        private byte[] getCompleteHw()
14        {
15            byte[] bDerHashIdent = Hex.Decode(Datablock.getInstance().HashFunctionIdent.DERIdent);
16            byte[] bMessage = Datablock.getInstance().Message;
17            HashFunctionIdent hashIdent = Datablock.getInstance().HashFunctionIdent;
18            byte[] hashDigest = Hashfunction.generateHashDigest(ref bMessage, ref hashIdent);         
19            byte[] returnArray = new byte[bDerHashIdent.Length + Hashfunction.getDigestSize()];
20            Array.Copy(bDerHashIdent, 0, returnArray, 0, bDerHashIdent.Length);
21            Array.Copy(hashDigest, 0, returnArray, returnArray.Length - hashDigest.Length, hashDigest.Length);
22
23            return returnArray;
24        }       
25
26        public override bool GenerateSignature()
27        {
28            if (RsaKey.Instance.isKeyGenerated())
29            {
30                // RSA Schlüssellänge setzen für Methode in Oberklasse
31                this.m_KeyLength = RsaKey.Instance.RsaKeySize;
32               
33                IAsymmetricBlockCipher signerPkcs1Enc = new Pkcs1Encoding(new RsaEngine());
34                signerPkcs1Enc.Init(true, RsaKey.Instance.getPrivKey());
35                byte[] output = signerPkcs1Enc.ProcessBlock(this.getCompleteHw(), 0, this.getCompleteHw().Length);
36 
37                this.m_bSigGenerated = true;
38                this.m_Signature = output;
39                this.OnRaiseSigGenEvent(SignatureType.Pkcs1);
40                return true;
41            }
42            return false;
43        }
44
45        #endregion //encrypted PKCS1 Signature
46    }
47}
Note: See TracBrowser for help on using the repository browser.