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

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

renamed some classes for the sake of consistency

File size: 2.1 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 RsaSig : Signature
18    {
19        #region encrypted PKCS1 Signature
20
21        private byte[] getCompleteHw()
22        {
23            byte[] bDerHashIdent = Hex.Decode(Datablock.getInstance().HashFunctionIdent.DERIdent);
24            byte[] bMessage = Datablock.getInstance().Message;
25            HashFunctionIdent hashIdent = Datablock.getInstance().HashFunctionIdent;
26            byte[] hashDigest = Hashfunction.generateHashDigest(ref bMessage, ref hashIdent);         
27            byte[] returnArray = new byte[bDerHashIdent.Length + Hashfunction.getDigestSize()];
28            Array.Copy(bDerHashIdent, 0, returnArray, 0, bDerHashIdent.Length);
29            Array.Copy(hashDigest, 0, returnArray, returnArray.Length - hashDigest.Length, hashDigest.Length);
30
31            return returnArray;
32        }       
33
34        public override bool GenerateSignature()
35        {
36            if (RsaKey.Instance.isKeyGenerated())
37            {
38                // RSA Schlüssellänge setzen für Methode in Oberklasse
39                this.m_KeyLength = RsaKey.Instance.RsaKeySize;
40
41                IAsymmetricBlockCipher signerPkcs1Enc = new Pkcs1Encoding(new RsaEngine());
42                signerPkcs1Enc.Init(true, RsaKey.Instance.getPrivKey());
43                byte[] output = signerPkcs1Enc.ProcessBlock(this.getCompleteHw(), 0, this.getCompleteHw().Length);
44 
45                this.m_bSigGenerated = true;
46                this.m_Signature = output;
47                this.OnRaiseSigGenEvent(SignatureType.Pkcs1);
48                return true;
49            }
50            return false;
51        }
52
53        #endregion //encrypted PKCS1 Signature
54    }
55}
Note: See TracBrowser for help on using the repository browser.