本文整理匯總了Java中java.security.Provider.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java Provider.equals方法的具體用法?Java Provider.equals怎麽用?Java Provider.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.Provider
的用法示例。
在下文中一共展示了Provider.equals方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testWolfSignInteropVerify
import java.security.Provider; //導入方法依賴的package包/類
@Test
public void testWolfSignInteropVerify()
throws NoSuchProviderException, NoSuchAlgorithmException,
SignatureException, InvalidKeyException,
InvalidAlgorithmParameterException {
String toSign = "Hello World";
byte[] toSignBuf = toSign.getBytes();
byte[] signature;
for (int i = 0; i < wolfJCEAlgos.length; i++) {
Signature signer =
Signature.getInstance(wolfJCEAlgos[i], "wolfJCE");
Signature verifier =
Signature.getInstance(wolfJCEAlgos[i]);
assertNotNull(signer);
assertNotNull(verifier);
Provider prov = verifier.getProvider();
if (prov.equals("wolfJCE")) {
/* bail out, there isn't another implementation to interop
* against by default */
return;
}
SecureRandom rand =
SecureRandom.getInstance("HashDRBG", "wolfJCE");
assertNotNull(rand);
/* generate key pair */
KeyPair pair = generateKeyPair(wolfJCEAlgos[i], rand);
assertNotNull(pair);
PrivateKey priv = pair.getPrivate();
PublicKey pub = pair.getPublic();
/* generate signature */
signer.initSign(priv);
signer.update(toSignBuf, 0, toSignBuf.length);
signature = signer.sign();
/* verify signature */
verifier.initVerify(pub);
verifier.update(toSignBuf, 0, toSignBuf.length);
boolean verified = verifier.verify(signature);
if (verified != true) {
fail("Signature verification failed when generating with " +
"wolfJCE and verifying with system default JCE " +
"provider");
}
}
}
示例2: testInteropSignWolfVerify
import java.security.Provider; //導入方法依賴的package包/類
@Test
public void testInteropSignWolfVerify()
throws NoSuchProviderException, NoSuchAlgorithmException,
SignatureException, InvalidKeyException,
InvalidAlgorithmParameterException {
String toSign = "Hello World";
byte[] toSignBuf = toSign.getBytes();
byte[] signature;
for (int i = 0; i < wolfJCEAlgos.length; i++) {
Signature signer =
Signature.getInstance(wolfJCEAlgos[i]);
Signature verifier =
Signature.getInstance(wolfJCEAlgos[i], "wolfJCE");
assertNotNull(signer);
assertNotNull(verifier);
Provider prov = signer.getProvider();
if (prov.equals("wolfJCE")) {
/* bail out, there isn't another implementation to interop
* against by default */
return;
}
SecureRandom rand =
SecureRandom.getInstance("HashDRBG", "wolfJCE");
assertNotNull(rand);
/* generate key pair */
KeyPair pair = generateKeyPair(wolfJCEAlgos[i], rand);
assertNotNull(pair);
PrivateKey priv = pair.getPrivate();
PublicKey pub = pair.getPublic();
/* generate signature */
signer.initSign(priv);
signer.update(toSignBuf, 0, toSignBuf.length);
signature = signer.sign();
/* verify signature */
verifier.initVerify(pub);
verifier.update(toSignBuf, 0, toSignBuf.length);
boolean verified = verifier.verify(signature);
if (verified != true) {
fail("Signature verification failed when generating with " +
"system default JCE provider and verifying with " +
"wolfJCE provider, iteration " + i);
}
}
}
示例3: testSha256Interop
import java.security.Provider; //導入方法依賴的package包/類
@Test
public void testSha256Interop()
throws NoSuchProviderException, NoSuchAlgorithmException {
String input = "Bozeman, MT";
String input2 = "wolfSSL is an Open Source Internet security " +
"company, focused primarily on SSL/TLS and " +
"cryptography. Main products include the wolfSSL " +
"embedded SSL/TLS library, wolfCrypt cryptography " +
"library, wolfMQTT, and wolfSSH. Products are " +
"dual licensed under both GPLv2 and a commercial" +
"license.";
byte[] wolfOutput;
byte[] interopOutput;
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
Provider provider = sha256.getProvider();
/* if we have another MessageDigest provider, test against it */
if (!provider.equals("wolfJCE")) {
/* short message */
sha256.update(input.getBytes());
interopOutput = sha256.digest();
MessageDigest wolfSha256 =
MessageDigest.getInstance("SHA-256", "wolfJCE");
wolfSha256.update(input.getBytes());
wolfOutput = wolfSha256.digest();
assertArrayEquals(wolfOutput, interopOutput);
/* long message */
sha256.update(input2.getBytes());
interopOutput = sha256.digest();
wolfSha256.update(input2.getBytes());
wolfOutput = wolfSha256.digest();
assertArrayEquals(wolfOutput, interopOutput);
}
}
示例4: testMd5Interop
import java.security.Provider; //導入方法依賴的package包/類
@Test
public void testMd5Interop()
throws NoSuchProviderException, NoSuchAlgorithmException {
String input = "Bozeman, MT";
String input2 = "wolfSSL is an Open Source Internet security " +
"company, focused primarily on SSL/TLS and " +
"cryptography. Main products include the wolfSSL " +
"embedded SSL/TLS library, wolfCrypt cryptography " +
"library, wolfMQTT, and wolfSSH. Products are " +
"dual licensed under both GPLv2 and a commercial" +
"license.";
byte[] wolfOutput;
byte[] interopOutput;
MessageDigest md5 = MessageDigest.getInstance("MD5");
Provider provider = md5.getProvider();
/* if we have another MessageDigest provider, test against it */
if (!provider.equals("wolfJCE")) {
/* short message */
md5.update(input.getBytes());
interopOutput = md5.digest();
MessageDigest wolfMd5 =
MessageDigest.getInstance("MD5", "wolfJCE");
wolfMd5.update(input.getBytes());
wolfOutput = wolfMd5.digest();
assertArrayEquals(wolfOutput, interopOutput);
/* long message */
md5.update(input2.getBytes());
interopOutput = md5.digest();
wolfMd5.update(input2.getBytes());
wolfOutput = wolfMd5.digest();
assertArrayEquals(wolfOutput, interopOutput);
}
}
示例5: testSha384Interop
import java.security.Provider; //導入方法依賴的package包/類
@Test
public void testSha384Interop()
throws NoSuchProviderException, NoSuchAlgorithmException {
String input = "Bozeman, MT";
String input2 = "wolfSSL is an Open Source Internet security " +
"company, focused primarily on SSL/TLS and " +
"cryptography. Main products include the wolfSSL " +
"embedded SSL/TLS library, wolfCrypt cryptography " +
"library, wolfMQTT, and wolfSSH. Products are " +
"dual licensed under both GPLv2 and a commercial" +
"license.";
byte[] wolfOutput;
byte[] interopOutput;
MessageDigest sha384 = MessageDigest.getInstance("SHA-384");
Provider provider = sha384.getProvider();
/* if we have another MessageDigest provider, test against it */
if (!provider.equals("wolfJCE")) {
/* short message */
sha384.update(input.getBytes());
interopOutput = sha384.digest();
MessageDigest wolfSha384 =
MessageDigest.getInstance("SHA-384", "wolfJCE");
wolfSha384.update(input.getBytes());
wolfOutput = wolfSha384.digest();
assertArrayEquals(wolfOutput, interopOutput);
/* long message */
sha384.update(input2.getBytes());
interopOutput = sha384.digest();
wolfSha384.update(input2.getBytes());
wolfOutput = wolfSha384.digest();
assertArrayEquals(wolfOutput, interopOutput);
}
}
示例6: testShaInterop
import java.security.Provider; //導入方法依賴的package包/類
@Test
public void testShaInterop()
throws NoSuchProviderException, NoSuchAlgorithmException {
String input = "Bozeman, MT";
String input2 = "wolfSSL is an Open Source Internet security " +
"company, focused primarily on SSL/TLS and " +
"cryptography. Main products include the wolfSSL " +
"embedded SSL/TLS library, wolfCrypt cryptography " +
"library, wolfMQTT, and wolfSSH. Products are " +
"dual licensed under both GPLv2 and a commercial" +
"license.";
byte[] wolfOutput;
byte[] interopOutput;
MessageDigest sha = MessageDigest.getInstance("SHA-1");
Provider provider = sha.getProvider();
/* if we have another MessageDigest provider, test against it */
if (!provider.equals("wolfJCE")) {
/* short message */
sha.update(input.getBytes());
interopOutput = sha.digest();
MessageDigest wolfSha =
MessageDigest.getInstance("SHA-1", "wolfJCE");
wolfSha.update(input.getBytes());
wolfOutput = wolfSha.digest();
assertArrayEquals(wolfOutput, interopOutput);
/* long message */
sha.update(input2.getBytes());
interopOutput = sha.digest();
wolfSha.update(input2.getBytes());
wolfOutput = wolfSha.digest();
assertArrayEquals(wolfOutput, interopOutput);
}
}
示例7: testDHKeyAgreementInterop
import java.security.Provider; //導入方法依賴的package包/類
@Test
public void testDHKeyAgreementInterop()
throws NoSuchProviderException, NoSuchAlgorithmException,
InvalidParameterSpecException, InvalidKeyException,
InvalidAlgorithmParameterException {
/* create DH params */
AlgorithmParameterGenerator paramGen =
AlgorithmParameterGenerator.getInstance("DH");
paramGen.init(512);
AlgorithmParameters params = paramGen.generateParameters();
DHParameterSpec dhParams =
(DHParameterSpec)params.getParameterSpec(DHParameterSpec.class);
/* initialize key pair generator */
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH", "wolfJCE");
keyGen.initialize(dhParams, new SecureRandom());
KeyAgreement aKeyAgree = KeyAgreement.getInstance("DH", "wolfJCE");
KeyAgreement bKeyAgree = KeyAgreement.getInstance("DH");
Provider prov = bKeyAgree.getProvider();
/* only run test if we have another provider besides ourselves */
if (!prov.equals("wolfJCE")) {
KeyPair aPair = keyGen.generateKeyPair();
KeyPair bPair = keyGen.generateKeyPair();
aKeyAgree.init(aPair.getPrivate());
bKeyAgree.init(bPair.getPrivate());
aKeyAgree.doPhase(bPair.getPublic(), true);
bKeyAgree.doPhase(aPair.getPublic(), true);
byte secretA[] = aKeyAgree.generateSecret();
byte secretB[] = bKeyAgree.generateSecret();
assertArrayEquals(secretA, secretB);
/* now, try reusing the A object without calling init() again */
KeyAgreement cKeyAgree = KeyAgreement.getInstance("DH", "wolfJCE");
KeyPair cPair = keyGen.generateKeyPair();
cKeyAgree.init(cPair.getPrivate());
aKeyAgree.doPhase(cPair.getPublic(), true);
cKeyAgree.doPhase(aPair.getPublic(), true);
byte secretA2[] = aKeyAgree.generateSecret();
byte secretC[] = cKeyAgree.generateSecret();
assertArrayEquals(secretA2, secretC);
}
}
示例8: testECDHKeyAgreementInterop
import java.security.Provider; //導入方法依賴的package包/類
@Test
public void testECDHKeyAgreementInterop()
throws NoSuchProviderException, NoSuchAlgorithmException,
InvalidParameterSpecException, InvalidKeyException,
InvalidAlgorithmParameterException {
/* initialize key pair generator */
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC", "wolfJCE");
ECGenParameterSpec ecsp = new ECGenParameterSpec("secp256r1");
keyGen.initialize(ecsp);
KeyAgreement aKeyAgree = KeyAgreement.getInstance("ECDH", "wolfJCE");
KeyAgreement bKeyAgree = KeyAgreement.getInstance("ECDH");
Provider prov = bKeyAgree.getProvider();
if (prov.equals("wolfJCE")) {
/* return, no other provider installed to interop against */
return;
}
KeyPair aPair = keyGen.generateKeyPair();
KeyPair bPair = keyGen.generateKeyPair();
aKeyAgree.init(aPair.getPrivate());
bKeyAgree.init(bPair.getPrivate());
aKeyAgree.doPhase(bPair.getPublic(), true);
bKeyAgree.doPhase(aPair.getPublic(), true);
byte secretA[] = aKeyAgree.generateSecret();
byte secretB[] = bKeyAgree.generateSecret();
assertArrayEquals(secretA, secretB);
/* now, try reusing the A object without calling init() again */
KeyAgreement cKeyAgree =
KeyAgreement.getInstance("ECDH", "wolfJCE");
KeyPair cPair = keyGen.generateKeyPair();
cKeyAgree.init(cPair.getPrivate());
aKeyAgree.doPhase(cPair.getPublic(), true);
cKeyAgree.doPhase(aPair.getPublic(), true);
byte secretA2[] = aKeyAgree.generateSecret();
byte secretC[] = cKeyAgree.generateSecret();
assertArrayEquals(secretA2, secretC);
}
示例9: testSha512Interop
import java.security.Provider; //導入方法依賴的package包/類
@Test
public void testSha512Interop()
throws NoSuchProviderException, NoSuchAlgorithmException {
String input = "Bozeman, MT";
String input2 = "wolfSSL is an Open Source Internet security " +
"company, focused primarily on SSL/TLS and " +
"cryptography. Main products include the wolfSSL " +
"embedded SSL/TLS library, wolfCrypt cryptography " +
"library, wolfMQTT, and wolfSSH. Products are " +
"dual licensed under both GPLv2 and a commercial" +
"license.";
byte[] wolfOutput;
byte[] interopOutput;
MessageDigest sha512 = MessageDigest.getInstance("SHA-512");
Provider provider = sha512.getProvider();
/* if we have another MessageDigest provider, test against it */
if (!provider.equals("wolfJCE")) {
/* short message */
sha512.update(input.getBytes());
interopOutput = sha512.digest();
MessageDigest wolfSha512 =
MessageDigest.getInstance("SHA-512", "wolfJCE");
wolfSha512.update(input.getBytes());
wolfOutput = wolfSha512.digest();
assertArrayEquals(wolfOutput, interopOutput);
/* long message */
sha512.update(input2.getBytes());
interopOutput = sha512.digest();
wolfSha512.update(input2.getBytes());
wolfOutput = wolfSha512.digest();
assertArrayEquals(wolfOutput, interopOutput);
}
}