private byte[] DerEncode(byte[] hash) { if (algId == null) { // For raw RSA, the DigestInfo must be prepared externally return hash; } DigestInfo dInfo = new DigestInfo(algId, hash); return dInfo.GetDerEncoded(); }
/// <summary> /// Creates PKCS#1 DigestInfo /// </summary> /// <param name="hash">Hash value</param> /// <param name="hashOid">Hash algorithm OID</param> /// <returns>DER encoded PKCS#1 DigestInfo</returns> private static byte[] CreateDigestInfo(byte[] hash, string hashOid) { DerObjectIdentifier derObjectIdentifier = new DerObjectIdentifier(hashOid); AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(derObjectIdentifier, null); DigestInfo digestInfo = new DigestInfo(algorithmIdentifier, hash); return digestInfo.GetDerEncoded(); }
private byte[] DerEncode( byte[] hash) { DigestInfo dInfo = new DigestInfo(algId, hash); return dInfo.GetDerEncoded(); }
/// <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); }*/ }