List of usage examples for org.bouncycastle.crypto.engines RSABlindedEngine init
public void init(boolean forEncryption, CipherParameters param)
From source file:bluecrystal.service.service.SignVerifyService.java
License:Open Source License
public boolean verify(int hashId, byte[] contentHash, byte[] sigBytes, X509Certificate cert) throws Exception { RSAPublicKey pubK = (RSAPublicKey) cert.getPublicKey(); CipherParameters param = new RSAKeyParameters(false, pubK.getModulus(), pubK.getPublicExponent()); RSABlindedEngine cipher2 = new RSABlindedEngine(); cipher2.init(false, param); AsymmetricBlockCipher cipher = new PKCS1Encoding(cipher2); byte[] sig = cipher.processBlock(sigBytes, 0, sigBytes.length); AlgorithmIdentifier algId = createAlgorithm(hashId); byte[] expected = derEncode(contentHash, algId); LOG.debug("Sig:(" + sigBytes.length + ")" + Utils.conv(sigBytes)); LOG.debug("Has:(" + contentHash.length + ")" + Utils.conv(contentHash)); LOG.debug("Sig:(" + sig.length + ")" + Utils.conv(sig)); LOG.debug("Exp:(" + expected.length + ")" + Utils.conv(expected)); if (sig.length == expected.length) { for (int i = 0; i < sig.length; i++) { if (sig[i] != expected[i]) { return false; }//from ww w . j a va 2s. co m } } else if (sig.length == expected.length - 2) // NULL left out { int sigOffset = sig.length - contentHash.length - 2; int expectedOffset = expected.length - contentHash.length - 2; expected[1] -= 2; // adjust lengths expected[3] -= 2; for (int i = 0; i < contentHash.length; i++) { if (sig[sigOffset + i] != expected[expectedOffset + i]) // check hash { return false; } } for (int i = 0; i < sigOffset; i++) { if (sig[i] != expected[i]) // check header less NULL { return false; } } } else { return false; } return true; }