本文整理汇总了Java中java.security.Provider类的典型用法代码示例。如果您正苦于以下问题:Java Provider类的具体用法?Java Provider怎么用?Java Provider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Provider类属于java.security包,在下文中一共展示了Provider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: installSecureRandomProvider
import java.security.Provider; //导入依赖的package包/类
private void installSecureRandomProvider(Provider provider) {
Provider[] providers = Security.getProviders("SecureRandom.SHA1PRNG");
if (providers == null || providers.length == 0
|| !provider.getClass().equals(providers[0].getClass())) {
Security.insertProviderAt(provider, 1);
}
// Check the new provider is the default when no algorithm is specified
SecureRandom random = new SecureRandom();
if (!provider.getClass().equals(random.getProvider().getClass())) {
throw new SecurityException("Wrong SecureRandom provider: "
+ random.getProvider().getClass());
}
// Check the new provider is the default when SHA1PRNG is specified
try {
random = SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
throw new SecurityException(e);
}
if (!provider.getClass().equals(random.getProvider().getClass())) {
throw new SecurityException("Wrong SHA1PRNG provider: "
+ random.getProvider().getClass());
}
}
示例2: main
import java.security.Provider; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Provider provider = Security.getProvider("SunJCE");
if (provider == null) {
throw new RuntimeException("SunJCE provider not exist");
}
// generate no-padding cipher with secret key
Cipher c = Cipher.getInstance("DES/CBC/NoPadding", provider);
KeyGenerator kgen = KeyGenerator.getInstance("DES", provider);
SecretKey skey = kgen.generateKey();
// this is the improperly padded plaintext
c.init(Cipher.ENCRYPT_MODE, skey);
// encrypt plaintext
byte[] cipher = c.doFinal(PLAIN_TEXT);
AlgorithmParameters params = c.getParameters();
// generate cipher that enforces PKCS5 padding
c = Cipher.getInstance("DES/CBC/PKCS5Padding", provider);
c.init(Cipher.DECRYPT_MODE, skey, params);
try {
c.doFinal(cipher);
throw new RuntimeException(
"ERROR: Expected BadPaddingException not thrown");
} catch (BadPaddingException expected) {
out.println("Expected BadPaddingException thrown");
}
}
示例3: ECKey
import java.security.Provider; //导入依赖的package包/类
/**
* Pair a private key with a public EC point.
*
* All private key operations will use the provider.
*/
public ECKey(Provider provider, @Nullable PrivateKey privKey, ECPoint pub) {
this.provider = provider;
if (privKey == null || isECPrivateKey(privKey)) {
this.privKey = privKey;
} else {
throw new IllegalArgumentException(
"Expected EC private key, given a private key object with class " +
privKey.getClass().toString() +
" and algorithm " + privKey.getAlgorithm());
}
if (pub == null) {
throw new IllegalArgumentException("Public key may not be null");
} else {
this.pub = pub;
}
}
示例4: main
import java.security.Provider; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Provider myProvider = new MyProvider();
Security.addProvider(myProvider);
System.out.println(Arrays.asList(Security.getProviders()));
TerminalFactory.getInstance("MyType", new Object()).terminals();
if (!callMethod) {
throw new RuntimeException("Expected engineTerminals() not called");
}
}
示例5: main
import java.security.Provider; //导入依赖的package包/类
public static void main(String[] args) {
PBESealedObject test = new PBESealedObject();
Provider sunjce = Security.getProvider("SunJCE");
if (!test.runAll(sunjce, System.out)) {
throw new RuntimeException("One or more tests have failed....");
}
}
示例6: verify
import java.security.Provider; //导入依赖的package包/类
/**
* Verifies that this CRL was signed using the
* private key that corresponds to the given public key,
* and that the signature verification was computed by
* the given provider. Note that the specified Provider object
* does not have to be registered in the provider list.
*
* @param key the PublicKey used to carry out the verification.
* @param sigProvider the signature provider.
*
* @exception NoSuchAlgorithmException on unsupported signature
* algorithms.
* @exception InvalidKeyException on incorrect key.
* @exception SignatureException on signature errors.
* @exception CRLException on encoding errors.
*/
public synchronized void verify(PublicKey key, Provider sigProvider)
throws CRLException, NoSuchAlgorithmException, InvalidKeyException,
SignatureException {
if (signedCRL == null) {
throw new CRLException("Uninitialized CRL");
}
Signature sigVerf = null;
if (sigProvider == null) {
sigVerf = Signature.getInstance(sigAlgId.getName());
} else {
sigVerf = Signature.getInstance(sigAlgId.getName(), sigProvider);
}
sigVerf.initVerify(key);
if (tbsCertList == null) {
throw new CRLException("Uninitialized CRL");
}
sigVerf.update(tbsCertList, 0, tbsCertList.length);
if (!sigVerf.verify(signature)) {
throw new SignatureException("Signature does not match.");
}
verifiedPublicKey = key;
}
示例7: main
import java.security.Provider; //导入依赖的package包/类
@Override
public void main(Provider p) throws Exception {
SecureRandom random;
try {
random = SecureRandom.getInstance("PKCS11");
} catch (NoSuchAlgorithmException e) {
System.out.println("Provider " + p + " does not support SecureRandom, skipping");
e.printStackTrace();
return;
}
byte[] b = new byte[32];
random.nextBytes(b);
System.out.println(toString(b));
random.setSeed(b);
random.nextBytes(b);
System.out.println(toString(b));
System.out.println("OK");
}
示例8: main
import java.security.Provider; //导入依赖的package包/类
@Override
public void main(Provider p) {
List<String> algorithms = getSupportedAlgorithms("Mac", "Hmac", p);
boolean success = true;
for (String alg : algorithms) {
try {
doTest(alg, p);
} catch (Exception e) {
System.out.println("Unexpected exception: " + e);
e.printStackTrace();
success = false;
}
}
if (!success) {
throw new RuntimeException("Test failed");
}
}
示例9: testProviderInstallationAtRuntime
import java.security.Provider; //导入依赖的package包/类
@BeforeClass
public static void testProviderInstallationAtRuntime() {
/* install wolfJCE provider at runtime */
Security.addProvider(new WolfCryptProvider());
Provider p = Security.getProvider("wolfJCE");
assertNotNull(p);
/* build list of enabled curves and key sizes,
* getCurveSizeFromName() will return 0 if curve not found */
Ecc tmp = new Ecc();
for (int i = 0; i < supportedCurves.length; i++) {
int size = tmp.getCurveSizeFromName(
supportedCurves[i].toUpperCase());
if (size > 0) {
enabledCurves.add(supportedCurves[i]);
if (!enabledKeySizes.contains(new Integer(size))) {
enabledKeySizes.add(new Integer(size));
}
}
}
}
示例10: testKeyAgreement
import java.security.Provider; //导入依赖的package包/类
private static void testKeyAgreement(KeyPair kpA, KeyPair kpB, Provider p)
throws Exception {
KeyAgreement ka1 = KeyAgreement.getInstance("ECDH", p);
ka1.init(kpA.getPrivate());
ka1.doPhase(kpB.getPublic(), true);
byte[] s1 = ka1.generateSecret();
KeyAgreement ka2 = KeyAgreement.getInstance("ECDH", p);
ka2.init(kpB.getPrivate());
ka2.doPhase(kpA.getPublic(), true);
byte[] s2 = ka2.generateSecret();
if (Arrays.equals(s1, s2) == false) {
System.out.println("expected: " + toString(s1));
System.out.println("actual: " + toString(s2));
throw new Exception("Generated secrets do not match");
}
}
示例11: crypt
import java.security.Provider; //导入依赖的package包/类
static byte[] crypt(
boolean encrypt,
String provider,
byte[] bytes,
char[] password,
String dekAlgName,
byte[] iv)
throws IOException
{
Provider prov = null;
if (provider != null)
{
prov = Security.getProvider(provider);
if (prov == null)
{
throw new EncryptionException("cannot find provider: " + provider);
}
}
return crypt(encrypt, prov, bytes, password, dekAlgName, iv);
}
示例12: testSigning
import java.security.Provider; //导入依赖的package包/类
private static void testSigning(Provider p, String algorithm,
byte[] data, KeyPair kp1, KeyPair kp2) throws Exception {
System.out.print(" " + algorithm);
Signature s = Signature.getInstance(algorithm, p);
s.initSign(kp1.getPrivate());
s.update(data);
byte[] sig = s.sign();
s = Signature.getInstance(algorithm, p);
s.initVerify(kp1.getPublic());
s.update(data);
boolean r = s.verify(sig);
if (r == false) {
throw new Exception("Signature did not verify");
}
s.initVerify(kp2.getPublic());
s.update(data);
r = s.verify(sig);
if (r) {
throw new Exception("Signature should not verify");
}
}
示例13: addAllMechsFromProvider
import java.security.Provider; //导入依赖的package包/类
/**
* Helper routine to go through all properties contined in a
* provider and add its mechanisms to the list of supported
* mechanisms. If no default mechanism has been assinged so far,
* it sets the default MechanismFactory and Oid as well.
* @param p the provider to query
* @return true if there is at least one mechanism that this
* provider contributed, false otherwise
*/
private boolean addAllMechsFromProvider(Provider p) {
String prop;
boolean retVal = false;
// Get all props for this provider
Enumeration<Object> props = p.keys();
// See if there are any GSS prop's
while (props.hasMoreElements()) {
prop = (String) props.nextElement();
if (isMechFactoryProperty(prop)) {
// Ok! This is a GSS provider!
try {
Oid mechOid = getOidFromMechFactoryProperty(prop);
mechs.add(mechOid);
retVal = true;
} catch (GSSException e) {
// Skip to next property
GSSUtil.debug("Ignore the invalid property " +
prop + " from provider " + p.getName());
}
} // Processed GSS property
} // while loop
return retVal;
}
示例14: AbstractXMLRSSTest
import java.security.Provider; //导入依赖的package包/类
public AbstractXMLRSSTest(String algorithm, Provider provider, KeyPair keyPair) {
Security.insertProviderAt(provider, 1);
this.algorithm = algorithm;
this.providerName = provider.getName();
this.provider = provider;
AbstractXMLRSSTest.keyPair = keyPair;
}
示例15: fromInstructionFile
import java.security.Provider; //导入依赖的package包/类
/**
* @return a non-null content crypto material.
*/
static ContentCryptoMaterial fromInstructionFile(
Map<String, String> instFile,
EncryptionMaterialsAccessor kekMaterialAccessor,
Provider securityProvider,
boolean keyWrapExpected,
AWSKMS kms) {
return fromInstructionFile0(instFile, kekMaterialAccessor,
securityProvider, null, NONE, keyWrapExpected, kms);
}