Example #1
0
        public byte[] EncryptRSA(byte[] data, RSA publicKey)
        {
            var cipher = CipherUtilities.GetCipher(RSA_CRYPTO_CIPHER);

            cipher.Init(true, BouncyCastleUtilities.GetRsaPublicKey(publicKey));
            cipher.ProcessBytes(data);
            return(cipher.DoFinal());
        }
Example #2
0
        public string GeneratePublicKeyFingerprintFromPrivateKey(RSA privateKey)
        {
            if (privateKey == null)
            {
                throw new ArgumentNullException(nameof(privateKey));
            }
            var keyInfo    = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(BouncyCastleUtilities.GetRsaPublicKey(privateKey));
            var keyBytes   = keyInfo.ToAsn1Object().GetDerEncoded();
            var hash       = DoHash(keyBytes, new MD5Digest());
            var hashString = ByteArrayUtils.ByteArrayToHexString(hash, ":");

            return(hashString);
        }