source: trunk/PKCS1/Library/RSASignature.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: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Security.Cryptography;
6using Org.BouncyCastle.Crypto;
7using Org.BouncyCastle.Security;
8using Org.BouncyCastle.Crypto.Generators;
9using Org.BouncyCastle.Crypto.Parameters;
10using Org.BouncyCastle.Crypto.Encodings;
11using Org.BouncyCastle.Crypto.Engines;
12using Org.BouncyCastle.Utilities.Encoders;
13using Org.BouncyCastle.Math;
14
15namespace PKCS1.Library
16{
17    public class RSASignature : Signature
18    {
19        #region encrypted PKCS1 Signature
20
21        private byte[] getCompleteHw()
22        {
23            byte[] hashIdent = Hex.Decode(Datablock.getInstance().HashFunctionIdent.DERIdent);
24            byte[] hashDigest = Hashfunction.generateHashDigest(Datablock.getInstance().Message, Datablock.getInstance().HashFunctionIdent);         
25            byte[] returnArray = new byte[hashIdent.Length + Hashfunction.getDigestSize()];
26            Array.Copy(hashIdent, 0, returnArray, 0, hashIdent.Length);
27            Array.Copy(hashDigest, 0, returnArray, returnArray.Length - hashDigest.Length, hashDigest.Length);
28
29            return returnArray;
30        }       
31
32        public override void GenerateSignature()
33        {
34            if (RSAKeyManager.getInstance().isKeyGenerated())
35            {
36                // RSA Schlüssellänge setzen für Methode in Oberklasse
37                this.m_KeyLength = RSAKeyManager.getInstance().RsaKeySize;
38
39                IAsymmetricBlockCipher signerPkcs1Enc = new Pkcs1Encoding(new RsaEngine());
40                signerPkcs1Enc.Init(true, RSAKeyManager.getInstance().getPrivKey());
41                byte[] output = signerPkcs1Enc.ProcessBlock(this.getCompleteHw(), 0, this.getCompleteHw().Length);
42 
43                this.m_bSigGenerated = true;
44                this.m_Signature = output;
45                this.OnRaiseSigGenEvent(SignatureType.Pkcs1);               
46            }
47        }
48
49        #endregion //encrypted PKCS1 Signature
50    }
51}
Note: See TracBrowser for help on using the repository browser.