Example #1
0
        public Signer GetSigner(Mode mode = Mode.Sign)
        {
            Signer result = null;
            String input = inputText.Text;

            switch (algorithmDrowdown.Text)
            {
                case "Цифровая подпись DSA":
                    if (dsaForm == null)
                    {
                        dsaForm = new DSAForm();
                    }
                    if (dsaForm.ShowDialog() == DialogResult.OK)
                    {
                        signKey = mode == Mode.Sign ? dsaForm.PrivateKey : dsaForm.PublicKey;
                        domain = dsaForm.Domain;
                        result = new DSASigner(dsaForm.Domain);
                    }
                    break;
                default:
                    throw new ArgumentException("Выберите метод подписи");
            }

            return result;
        }
Example #2
0
        public Signer GetSigner(Mode mode = Mode.Sign)
        {
            Signer result = null;
            String input  = inputText.Text;

            switch (algorithmDrowdown.Text)
            {
            case "Цифровая подпись DSA":
                if (dsaForm == null)
                {
                    dsaForm = new DSAForm();
                }
                if (dsaForm.ShowDialog() == DialogResult.OK)
                {
                    signKey = mode == Mode.Sign ? dsaForm.PrivateKey : dsaForm.PublicKey;
                    domain  = dsaForm.Domain;
                    result  = new DSASigner(dsaForm.Domain);
                }
                break;

            default:
                throw new ArgumentException("Выберите метод подписи");
            }

            return(result);
        }
Example #3
0
 private void Generate()
 {
     int minQ = (int)sbMinQ.Value;
     int maxQ = (int)sbMaxQ.Value;
     Domain = DomainParameters.GenerateDomainParameters(minQ, maxQ);
     generator = new DSAKeyGenerator(Domain);
     PrivateKey = generator.PrivateKey;
     PublicKey = generator.PublicKey;
 }
Example #4
0
        public void GenerateKeys()
        {
            BigInteger x, y;

            x = numbers.Next(0, Domain.Q);
            y = BigInteger.ModPow(Domain.G, x, Domain.P);

            PrivateKey = new SignKey(x);
            PublicKey  = new SignKey(y);
        }
Example #5
0
        public BigInteger decryptedDigest(DSASignedString signedText, SignKey key)
        {
            BigInteger w  = signedText.S.ModInverse(Domain.Q);
            BigInteger d  = digest(signedText.Text);
            BigInteger u1 = (d * w) % Domain.Q;
            BigInteger u2 = (signedText.R * w) % Domain.Q;
            BigInteger v  = ((BigInteger.ModPow(Domain.G, u1, Domain.P) * BigInteger.ModPow(key.Value, u2, Domain.P)) % Domain.P) % Domain.Q;

            CheckSignatureIntermediateValues = String.Format("W: {0:D}, h(M'): {1:D}, u1: {2:D}, u2: {3:D}, V: {4:D}, R: {5:D}, S: {6:D}, Y: {7:D}", w, d, u1, u2, v, signedText.R, signedText.S, key.Value);
            return(v);
        }
Example #6
0
        public DSASignedString sign(string text, SignKey key)
        {
            BigInteger d;

            do
            {
                K = numbers.Next(1, Domain.Q);
                R = BigInteger.ModPow(Domain.G, K, Domain.P) % Domain.Q;
                d = digest(text);
                S = (K.ModInverse(Domain.Q) * (d + key.Value * R)) % Domain.Q;
            } while (R == 0 || S == 0);
            SignIntermediateValues = String.Format("K: {0:D}, R: {1:D}, S: {2:D}, h(M): {3:D}, X: {4:D}", K, R, S, d, key.Value);
            return(new DSASignedString(text, R, S));
        }
Example #7
0
 public DSASignedString sign(string text, SignKey key)
 {
     BigInteger d;
     do
     {
         K = numbers.Next(1, Domain.Q);
         R = BigInteger.ModPow(Domain.G, K, Domain.P) % Domain.Q;
         d = digest(text);
         S = (K.ModInverse(Domain.Q) * (d + key.Value * R)) % Domain.Q;
     } while (R == 0 || S == 0);
     SignIntermediateValues = String.Format("K: {0:D}, R: {1:D}, S: {2:D}, h(M): {3:D}, X: {4:D}", K, R, S, d, key.Value);
     return new DSASignedString(text, R, S);
 }
Example #8
0
 public BigInteger decryptedDigest(DSASignedString signedText, SignKey key)
 {
     BigInteger w = signedText.S.ModInverse(Domain.Q);
     BigInteger d = digest(signedText.Text);
     BigInteger u1 = (d * w) % Domain.Q;
     BigInteger u2 = (signedText.R * w) % Domain.Q;
     BigInteger v = ((BigInteger.ModPow(Domain.G, u1, Domain.P) * BigInteger.ModPow(key.Value, u2, Domain.P)) % Domain.P) % Domain.Q;
     CheckSignatureIntermediateValues = String.Format("W: {0:D}, h(M'): {1:D}, u1: {2:D}, u2: {3:D}, V: {4:D}, R: {5:D}, S: {6:D}, Y: {7:D}", w, d, u1, u2, v, signedText.R, signedText.S, key.Value);
     return v;
 }
Example #9
0
 public bool checkSignature(DSASignedString signedText, SignKey key)
 {
     return decryptedDigest(signedText, key) == signedText.R;
 }
Example #10
0
        public void GenerateKeys()
        {
            BigInteger x, y;
            x = numbers.Next(0, Domain.Q);
            y = BigInteger.ModPow(Domain.G, x, Domain.P);

            PrivateKey = new SignKey(x);
            PublicKey = new SignKey(y);
        }
Example #11
0
 public bool checkSignature(DSASignedString signedText, SignKey key)
 {
     return(decryptedDigest(signedText, key) == signedText.R);
 }