Ejemplo n.º 1
0
        private Boolean verifyCamelotPSS(RSAParameters rsaParams, string hashAlgorithm, byte[] plainBytes, byte[] signatureBytes)
        {
            try
            {
                camelot.RSAManaged myRsaCsp =
                    new camelot.RSAManaged(null, rsaParams.Exponent, rsaParams.Modulus);

                camelot.HashAlgorithm hashAlg = selectCamelotHashAlgorithm(hashAlgorithm);

                // Decrypt using Camelot OAEP + SHA2
                camelot.RSAPSSSignatureDeformatter netPssDeformatter =
                    new camelot.RSAPSSSignatureDeformatter(myRsaCsp, hashAlg);

                Boolean verified =
                    netPssDeformatter.VerifySignature(plainBytes, signatureBytes);

                return(verified);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        private byte[] encryptCamelotOAEP(RSAParameters rsaParams, string hashAlgorithm, byte[] plainBytes)
        {
            try
            {
                camelot.RSAManaged myRsaCsp =
                    new camelot.RSAManaged(null, rsaParams.Exponent, rsaParams.Modulus);

                camelot.HashAlgorithm hashAlg = selectCamelotHashAlgorithm(hashAlgorithm);

                // Decrypt using Camelot OAEP + SHA2
                camelot.RSAOAEPKeyExchangeFormatter netOaepFormatter =
                    new camelot.RSAOAEPKeyExchangeFormatter(myRsaCsp, hashAlg, rng);

                byte[] cipherBytes =
                    netOaepFormatter.CreateKeyExchange(plainBytes);

                return(cipherBytes);
            }
            catch (Exception ex)
            {
                return(ByteConverter.GetBytes(ex.Message));
            }
        }
Ejemplo n.º 3
0
        private byte[] signCamelotPSS(RSAParameters rsaParams, string hashAlgorithm, byte[] plainBytes)
        {
            try
            {
                camelot.RSAManaged myRsaCsp =
                    new camelot.RSAManaged(rsaParams.D, null, rsaParams.Modulus);

                camelot.HashAlgorithm hashAlg = selectCamelotHashAlgorithm(hashAlgorithm);

                // Decrypt using Camelot OAEP + SHA2
                camelot.RSAPSSSignatureFormatter netPssFormatter =
                    new camelot.RSAPSSSignatureFormatter(myRsaCsp, hashAlg, rng);

                byte[] signatureBytes =
                    netPssFormatter.CreateSignature(plainBytes);

                return(signatureBytes);
            }
            catch (Exception ex)
            {
                return(ByteConverter.GetBytes(ex.Message));
            }
        }
Ejemplo n.º 4
0
        private byte[] decryptCamelotOAEP(RSAParameters rsaParams, string hashAlgorithm, byte[] cipherBytes)
        {
            try
            {
                camelot.RSAManaged myRsaCsp =
                    new camelot.RSAManaged(rsaParams.D, null, rsaParams.Modulus);

                camelot.HashAlgorithm hashAlg = selectCamelotHashAlgorithm(hashAlgorithm);

                // Decrypt using Camelot OAEP + SHA2
                camelot.RSAOAEPKeyExchangeDeformatter netOaepDeformatter1 =
                    new camelot.RSAOAEPKeyExchangeDeformatter(myRsaCsp, hashAlg);

                byte[] decryptedActual =
                    netOaepDeformatter1.DecryptKeyExchange(cipherBytes);

                return(decryptedActual);
            }
            catch (Exception ex)
            {
                return(ByteConverter.GetBytes(ex.Message));
            }
        }