本文整理汇总了Java中org.bouncycastle.crypto.signers.ISO9796d2Signer类的典型用法代码示例。如果您正苦于以下问题:Java ISO9796d2Signer类的具体用法?Java ISO9796d2Signer怎么用?Java ISO9796d2Signer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISO9796d2Signer类属于org.bouncycastle.crypto.signers包,在下文中一共展示了ISO9796d2Signer类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sign
import org.bouncycastle.crypto.signers.ISO9796d2Signer; //导入依赖的package包/类
private static byte[] sign() throws Exception {
RSAEngine rsa = new RSAEngine();
Digest dig = new SHA1Digest();
RSAPrivateKey privateKey = (RSAPrivateKey) getPrivate(privateKeyFilename);
BigInteger big = ((RSAKey) privateKey).getModulus();
ISO9796d2Signer eng = new ISO9796d2Signer(rsa, dig, true);
RSAKeyParameters rsaPriv = new RSAKeyParameters(true, big, privateKey.getPrivateExponent());
eng.init(true, rsaPriv);
eng.update(message[0]);
eng.update(message, 1, message.length - 1);
byte[] signature = eng.generateSignature();
return signature;
}
示例2: verify
import org.bouncycastle.crypto.signers.ISO9796d2Signer; //导入依赖的package包/类
private static String verify() throws Exception {
RSAEngine engine = new RSAEngine();
Digest digest = new SHA1Digest();
RSAPublicKey publicKey = (RSAPublicKey) getPublic(publicKeyFilename);
BigInteger big = ((RSAKey) publicKey).getModulus();
RSAKeyParameters rsaPublic = new RSAKeyParameters(false, big, publicKey.getPublicExponent());
ISO9796d2Signer verifier = new ISO9796d2Signer(engine, digest, true);
verifier.init(false, rsaPublic); // false for verify
if (!verifier.verifySignature(signature)) {
System.err.println("Signature was modified, could not verify correctness!");
return "";
}
String recoveredMessage = "";
try {
if (verifier.hasFullMessage()) {
verifier.updateWithRecoveredMessage(signature);
}
byte[] message = verifier.getRecoveredMessage();
recoveredMessage = new String(message, "UTF-8");
} catch (Exception exception) {
System.err.println("Recover failed!");
}
return recoveredMessage;
}
示例3: ISOSignatureSpi
import org.bouncycastle.crypto.signers.ISO9796d2Signer; //导入依赖的package包/类
protected ISOSignatureSpi(
Digest digest,
AsymmetricBlockCipher cipher)
{
super(digest.getAlgorithmName() + "withRSA/ISO9796-2");
signer = new ISO9796d2Signer(cipher, digest, true);
}
示例4: ISOSignatureSpi
import org.bouncycastle.crypto.signers.ISO9796d2Signer; //导入依赖的package包/类
protected ISOSignatureSpi(
Digest digest,
AsymmetricBlockCipher cipher)
{
signer = new ISO9796d2Signer(cipher, digest, true);
}
示例5: doTest12
import org.bouncycastle.crypto.signers.ISO9796d2Signer; //导入依赖的package包/类
public void doTest12()
throws Exception
{
BigInteger mod = new BigInteger("B3ABE6D91A4020920F8B3847764ECB34C4EB64151A96FDE7B614DC986C810FF2FD73575BDF8532C06004C8B4C8B64F700A50AEC68C0701ED10E8D211A4EA554D", 16);
BigInteger pubExp = new BigInteger("65537", 10);
BigInteger priExp = new BigInteger("AEE76AE4716F77C5782838F328327012C097BD67E5E892E75C1356E372CCF8EE1AA2D2CBDFB4DA19F703743F7C0BA42B2D69202BA7338C294D1F8B6A5771FF41", 16);
RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod, pubExp);
RSAKeyParameters privParameters = new RSAKeyParameters(true, mod, priExp);
RSAEngine rsa = new RSAEngine();
byte[] data;
byte[] m1 = {1, 2, 3, 4, 5, 6, 7, 8, 9};
byte[] m2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
byte[] m3 = {1, 2, 3, 4, 5, 6, 7, 8};
//
// ISO 9796-2 - Signing
//
Digest dig = new SHA1Digest();
ISO9796d2Signer eng = new ISO9796d2Signer(rsa, dig);
//
// check message bounds
//
eng.init(true, privParameters);
eng.update(m1, 0, m1.length);
data = eng.generateSignature();
eng.init(false, pubParameters);
eng.update(m2, 0, m2.length);
if (eng.verifySignature(data))
{
fail("failed ISO9796-2 m2 verify Test 12");
}
eng.init(false, pubParameters);
eng.update(m3, 0, m3.length);
if (eng.verifySignature(data))
{
fail("failed ISO9796-2 m3 verify Test 12");
}
eng.init(false, pubParameters);
eng.update(m1, 0, m1.length);
if (!eng.verifySignature(data))
{
fail("failed ISO9796-2 verify Test 12");
}
}