示例#1
0
        /// <exception cref="Sharpen.NoSuchAlgorithmException"></exception>
        public override byte[] EncryptDigest(byte[] digestValue, DigestAlgorithm digestAlgo
                                             , IDssPrivateKeyEntry keyEntry)
        {
            try
            {
                DigestInfo digestInfo = new DigestInfo(digestAlgo.GetAlgorithmIdentifier(), digestValue
                                                       );

                //Sharpen.Cipher cipher = Sharpen.Cipher.GetInstance(keyEntry.GetSignatureAlgorithm
                //    ().GetPadding());

                IBufferedCipher cipher = CipherUtilities.GetCipher(keyEntry.GetSignatureAlgorithm
                                                                       ().GetPadding());

                //cipher.Init(Sharpen.Cipher.ENCRYPT_MODE, ((KSPrivateKeyEntry)keyEntry).GetPrivateKey
                //    ());

                cipher.Init(true, ((KSPrivateKeyEntry)keyEntry).PrivateKey);

                return(cipher.DoFinal(digestInfo.GetDerEncoded()));
            }

            /*catch (NoSuchPaddingException e)
             * {
             *  throw new RuntimeException(e);
             * }*/
            catch (InvalidKeyException e)
            {
                throw new RuntimeException(e);
            }

            /*catch (IllegalBlockSizeException e)
             * {
             *  throw new RuntimeException(e);
             * }
             * catch (BadPaddingException)
             * {
             *  // More likely the password is not good.
             *  throw new BadPasswordException(BadPasswordException.MSG.PKCS12_BAD_PASSWORD);
             * }*/
        }
示例#2
0
        /// <exception cref="Sharpen.NoSuchAlgorithmException"></exception>
        public override byte[] EncryptDigest(byte[] digestValue, DigestAlgorithm digestAlgo
            , IDssPrivateKeyEntry keyEntry)
        {
            try
            {
                DigestInfo digestInfo = new DigestInfo(digestAlgo.GetAlgorithmIdentifier(), digestValue
                    );

                //Sharpen.Cipher cipher = Sharpen.Cipher.GetInstance(keyEntry.GetSignatureAlgorithm
                //    ().GetPadding());

                IBufferedCipher cipher = CipherUtilities.GetCipher(keyEntry.GetSignatureAlgorithm
                    ().GetPadding());

                //cipher.Init(Sharpen.Cipher.ENCRYPT_MODE, ((KSPrivateKeyEntry)keyEntry).GetPrivateKey
                //    ());

                cipher.Init(true, ((KSPrivateKeyEntry)keyEntry).PrivateKey);

                return cipher.DoFinal(digestInfo.GetDerEncoded());
            }
            /*catch (NoSuchPaddingException e)
            {
                throw new RuntimeException(e);
            }*/
            catch (InvalidKeyException e)
            {
                throw new RuntimeException(e);
            }
            /*catch (IllegalBlockSizeException e)
            {
                throw new RuntimeException(e);
            }
            catch (BadPaddingException)
            {
                // More likely the password is not good.
                throw new BadPasswordException(BadPasswordException.MSG.PKCS12_BAD_PASSWORD);
            }*/
        }