本文整理汇总了Java中java.security.Provider.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Provider.getName方法的具体用法?Java Provider.getName怎么用?Java Provider.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.Provider
的用法示例。
在下文中一共展示了Provider.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ECKey
import java.security.Provider; //导入方法依赖的package包/类
/**
* Generate a new keypair using the given Java Security Provider.
*
* All private key operations will use the provider.
*/
public ECKey(Provider provider, SecureRandom secureRandom) {
this.provider = provider;
KeyPairGenerator keyPairGen = ECKeyPairGenerator.getInstance(provider, secureRandom);
KeyPair keyPair = keyPairGen.generateKeyPair();
this.privKey = keyPair.getPrivate();
PublicKey pubKey = keyPair.getPublic();
if (pubKey instanceof BCECPublicKey) {
pub = ((BCECPublicKey) pubKey).getQ();
} else if (pubKey instanceof ECPublicKey) {
pub = extractPublicKey((ECPublicKey) pubKey);
} else {
throw new AssertionError("Expected Provider "
+ provider.getName()
+ " to produce a subtype of ECPublicKey, found "
+ pubKey.getClass());
}
}
示例2: run
import java.security.Provider; //导入方法依赖的package包/类
private void run() throws Exception {
Provider[] providers = Security.getProviders();
for (Provider p : providers) {
String prvName = p.getName();
if (prvName.startsWith("SunJCE")
|| prvName.startsWith("SunPKCS11-")) {
for (String algorithm : ALGORITHM_ARR) {
if (!runTest(p, algorithm)) {
throw new RuntimeException(
"Test failed with provider/algorithm:"
+ p.getName() + "/" + algorithm);
} else {
out.println("Test passed with provider/algorithm:"
+ p.getName() + "/" + algorithm);
}
}
}
}
}
示例3: ECKey
import java.security.Provider; //导入方法依赖的package包/类
/**
* Generate a new keypair using the given Java Security Provider.
*
* All private key operations will use the provider.
*/
public ECKey(Provider provider, SecureRandom secureRandom) {
this.provider = provider;
final KeyPairGenerator keyPairGen = ECKeyPairGenerator.getInstance(provider, secureRandom);
final KeyPair keyPair = keyPairGen.generateKeyPair();
this.privKey = keyPair.getPrivate();
final PublicKey pubKey = keyPair.getPublic();
if (pubKey instanceof BCECPublicKey) {
pub = ((BCECPublicKey) pubKey).getQ();
} else if (pubKey instanceof ECPublicKey) {
pub = extractPublicKey((ECPublicKey) pubKey);
} else {
throw new AssertionError(
"Expected Provider " + provider.getName() +
" to produce a subtype of ECPublicKey, found " + pubKey.getClass());
}
}
示例4: main
import java.security.Provider; //导入方法依赖的package包/类
public static void main(String args[]) {
String[] algorithms = { "SHA3-224", "SHA3-256", "SHA3-384",
"SHA3-512" };
for (Provider prov : Security.getProviders()) {
for (String algo : algorithms) {
try {
String provName = prov.getName();
MessageDigest md = MessageDigest.getInstance(algo, prov);
if (!isSHA3Supported(provName)) {
throw new RuntimeException("SHA-3 is not supported by "
+ provName + " provider, but expected "
+ "NoSuchAlgorithmException is not thrown");
}
} catch (NoSuchAlgorithmException ex) {
if (isSHA3Supported(prov.getName())) {
throw new RuntimeException("SHA-3 should be supported "
+ "by " + prov.getName() + " provider, got"
+ " unexpected NoSuchAlgorithmException");
}
continue;
}
}
}
}
示例5: AbstractRSSTest
import java.security.Provider; //导入方法依赖的package包/类
public AbstractRSSTest(String algorithm, Provider provider, KeyPair keyPair) {
Security.insertProviderAt(provider, 1);
this.algorithm = algorithm;
this.providerName = provider.getName();
this.provider = provider;
AbstractRSSTest.keyPair = keyPair;
}
示例6: run
import java.security.Provider; //导入方法依赖的package包/类
public void run() throws Exception {
Provider[] providers = Security.getProviders();
for (Provider p: providers) {
String prvName = p.getName();
if (prvName.startsWith("SunJCE")
|| prvName.startsWith("SunPKCS11-Solaris")) {
try {
runTest(p);
out.println("Test with provider " + p.getName() + ""
+ " passed");
} catch (java.security.KeyStoreException e) {
if (prvName.startsWith("SunPKCS11-Solaris")) {
out.println("KeyStoreException is expected because "
+ "PKCS11KeyStore is invalid keystore type.");
e.printStackTrace();
} else {
throw e;
}
}
}
}
}
示例7: if
import java.security.Provider; //导入方法依赖的package包/类
/**
* Returns a <code>TransformService</code> that supports the specified
* algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
* (ex: DOM) as supplied by the specified provider. Note that the specified
* <code>Provider</code> object does not have to be registered in the
* provider list.
*
* @param algorithm the URI of the algorithm
* @param mechanismType the type of the XML processing mechanism and
* representation
* @param provider the <code>Provider</code> object
* @return a new <code>TransformService</code>
* @throws NullPointerException if <code>provider</code>,
* <code>algorithm</code>, or <code>mechanismType</code> is
* <code>null</code>
* @throws NoSuchAlgorithmException if a <code>TransformService</code>
* implementation for the specified algorithm and mechanism type is not
* available from the specified <code>Provider</code> object
* @see Provider
*/
public static TransformService getInstance
(String algorithm, String mechanismType, Provider provider)
throws NoSuchAlgorithmException {
if (mechanismType == null || algorithm == null || provider == null) {
throw new NullPointerException();
}
boolean dom = false;
if (mechanismType.equals("DOM")) {
dom = true;
}
Service s = provider.getService("TransformService", algorithm);
if (s != null) {
String value = s.getAttribute("MechanismType");
if ((value == null && dom) ||
(value != null && value.equals(mechanismType))) {
Object obj = s.newInstance(null);
if (obj instanceof TransformService) {
TransformService ts = (TransformService) obj;
ts.algorithm = algorithm;
ts.mechanism = mechanismType;
ts.provider = provider;
return ts;
}
}
}
throw new NoSuchAlgorithmException
(algorithm + " algorithm and " + mechanismType
+ " mechanism not available from " + provider.getName());
}
示例8: 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;
}
示例9: getInstance
import java.security.Provider; //导入方法依赖的package包/类
/**
* Returns an <code>XMLSignatureFactory</code> that supports the
* requested XML processing mechanism and representation type (ex: "DOM"),
* as supplied by the specified provider. Note that the specified
* <code>Provider</code> object does not have to be registered in the
* provider list.
*
* @param mechanismType the type of the XML processing mechanism and
* representation. See the {@extLink security_guide_xmldsig_provider
* Service Providers} section of the API overview for a list of
* standard mechanism types.
* @param provider the <code>Provider</code> object
* @return a new <code>XMLSignatureFactory</code>
* @throws NullPointerException if <code>provider</code> or
* <code>mechanismType</code> is <code>null</code>
* @throws NoSuchMechanismException if an <code>XMLSignatureFactory</code>
* implementation for the specified mechanism is not available
* from the specified <code>Provider</code> object
* @see Provider
*/
public static XMLSignatureFactory getInstance(String mechanismType,
Provider provider) {
if (mechanismType == null) {
throw new NullPointerException("mechanismType cannot be null");
} else if (provider == null) {
throw new NullPointerException("provider cannot be null");
}
Service s = provider.getService("XMLSignatureFactory", mechanismType);
if (s != null) {
Object obj = null;
try {
obj = s.newInstance(null);
} catch (NoSuchAlgorithmException nsae) {
throw new NoSuchMechanismException(nsae);
}
if (obj instanceof XMLSignatureFactory) {
XMLSignatureFactory factory = (XMLSignatureFactory) obj;
factory.mechanismType = mechanismType;
factory.provider = provider;
return factory;
}
}
throw new NoSuchMechanismException
("Mechanism " + mechanismType + " not available from " +
provider.getName());
}
示例10: addProviderAtFront
import java.security.Provider; //导入方法依赖的package包/类
synchronized public void addProviderAtFront(Provider p, Oid mechOid)
throws GSSException {
PreferencesEntry newEntry = new PreferencesEntry(p, mechOid);
PreferencesEntry oldEntry;
boolean foundSomeMech;
Iterator<PreferencesEntry> list = preferences.iterator();
while (list.hasNext()) {
oldEntry = list.next();
if (newEntry.implies(oldEntry))
list.remove();
}
if (mechOid == null) {
foundSomeMech = addAllMechsFromProvider(p);
} else {
String oidStr = mechOid.toString();
if (p.getProperty(PROV_PROP_PREFIX + oidStr) == null)
throw new GSSExceptionImpl(GSSException.BAD_MECH,
"Provider " + p.getName()
+ " does not support "
+ oidStr);
mechs.add(mechOid);
foundSomeMech = true;
}
if (foundSomeMech) {
preferences.add(0, newEntry);
}
}
示例11: addProviderAtEnd
import java.security.Provider; //导入方法依赖的package包/类
synchronized public void addProviderAtEnd(Provider p, Oid mechOid)
throws GSSException {
PreferencesEntry newEntry = new PreferencesEntry(p, mechOid);
PreferencesEntry oldEntry;
boolean foundSomeMech;
Iterator<PreferencesEntry> list = preferences.iterator();
while (list.hasNext()) {
oldEntry = list.next();
if (oldEntry.implies(newEntry))
return;
}
// System.out.println("addProviderAtEnd: No it is not redundant");
if (mechOid == null)
foundSomeMech = addAllMechsFromProvider(p);
else {
String oidStr = mechOid.toString();
if (p.getProperty(PROV_PROP_PREFIX + oidStr) == null)
throw new GSSExceptionImpl(GSSException.BAD_MECH,
"Provider " + p.getName()
+ " does not support "
+ oidStr);
mechs.add(mechOid);
foundSomeMech = true;
}
if (foundSomeMech) {
preferences.add(newEntry);
}
}
示例12: getInstance
import java.security.Provider; //导入方法依赖的package包/类
/**
* Returns a <code>KeyInfoFactory</code> that supports the
* requested XML processing mechanism and representation type (ex: "DOM"),
* as supplied by the specified provider. Note that the specified
* <code>Provider</code> object does not have to be registered in the
* provider list.
*
* @param mechanismType the type of the XML processing mechanism and
* representation. See the <a href=
* "{@docRoot}/../specs/security/standard-names.html#xml-signature-xmlsignaturefactorykeyinfofactorytransformservice-mechanisms">
* Java Security Standard Algorithm Names</a> document
* for more information.
* @param provider the <code>Provider</code> object
* @return a new <code>KeyInfoFactory</code>
* @throws NullPointerException if <code>mechanismType</code> or
* <code>provider</code> are <code>null</code>
* @throws NoSuchMechanismException if a <code>KeyInfoFactory</code>
* implementation for the specified mechanism is not available from the
* specified <code>Provider</code> object
* @see Provider
*/
public static KeyInfoFactory getInstance(String mechanismType,
Provider provider) {
if (mechanismType == null) {
throw new NullPointerException("mechanismType cannot be null");
} else if (provider == null) {
throw new NullPointerException("provider cannot be null");
}
Service s = provider.getService("KeyInfoFactory", mechanismType);
if (s != null) {
Object obj = null;
try {
obj = s.newInstance(null);
} catch (NoSuchAlgorithmException nsae) {
throw new NoSuchMechanismException(nsae);
}
if (obj instanceof KeyInfoFactory) {
KeyInfoFactory factory = (KeyInfoFactory) obj;
factory.mechanismType = mechanismType;
factory.provider = provider;
return factory;
}
}
throw new NoSuchMechanismException
("Mechanism " + mechanismType + " not available from " + provider.getName());
}
示例13: getMechFactory
import java.security.Provider; //导入方法依赖的package包/类
/**
* Helper routine that uses a preferences entry to obtain an
* implementation of a MechanismFactory from it.
* @param e the preferences entry that contains the provider and
* either a null of an explicit oid that matched the oid of the
* desired mechanism.
* @param mechOid the oid of the desired mechanism
* @throws GSSException If the application explicitly requested
* this entry's provider to be used for the desired mechanism but
* some problem is encountered
*/
private MechanismFactory getMechFactory(PreferencesEntry e, Oid mechOid)
throws GSSException {
Provider p = e.getProvider();
/*
* See if a MechanismFactory was previously instantiated for
* this provider and mechanism combination.
*/
PreferencesEntry searchEntry = new PreferencesEntry(p, mechOid);
MechanismFactory retVal = factories.get(searchEntry);
if (retVal == null) {
/*
* Apparently not. Now try to instantiate this class from
* the provider.
*/
String prop = PROV_PROP_PREFIX + mechOid.toString();
String className = p.getProperty(prop);
if (className != null) {
retVal = getMechFactoryImpl(p, className, mechOid, caller);
factories.put(searchEntry, retVal);
} else {
/*
* This provider does not support this mechanism.
* If the application explicitly requested that
* this provider be used for this mechanism, then
* throw an exception
*/
if (e.getOid() != null) {
throw new GSSExceptionImpl(GSSException.BAD_MECH,
"Provider " + p.getName() +
" does not support mechanism " + mechOid);
}
}
}
return retVal;
}
示例14: createGSSException
import java.security.Provider; //导入方法依赖的package包/类
private static GSSException createGSSException(Provider p,
String className,
String trailingMsg,
Exception cause) {
String errClassInfo = className + " configured by " +
p.getName() + " for GSS-API Mechanism Factory ";
return new GSSExceptionImpl(GSSException.BAD_MECH,
errClassInfo + trailingMsg,
cause);
}
示例15: generateCEK
import java.security.Provider; //导入方法依赖的package包/类
/**
* @param kekMaterials non-null encryption materials
*/
protected final SecretKey generateCEK(
final EncryptionMaterials kekMaterials,
final Provider providerIn) {
final String keygenAlgo = contentCryptoScheme.getKeyGeneratorAlgorithm();
KeyGenerator generator;
try {
generator = providerIn == null
? KeyGenerator.getInstance(keygenAlgo)
: KeyGenerator.getInstance(keygenAlgo, providerIn);
generator.init(contentCryptoScheme.getKeyLengthInBits(),
cryptoScheme.getSecureRandom());
// Set to true iff the key encryption involves the use of BC's public key
boolean involvesBCPublicKey = false;
KeyPair keypair = kekMaterials.getKeyPair();
if (keypair != null) {
String keyWrapAlgo = cryptoScheme.getKeyWrapScheme().getKeyWrapAlgorithm(keypair.getPublic());
if (keyWrapAlgo == null) {
Provider provider = generator.getProvider();
String providerName = provider == null ? null : provider.getName();
involvesBCPublicKey = CryptoRuntime.BOUNCY_CASTLE_PROVIDER.equals(providerName);
}
}
SecretKey secretKey = generator.generateKey();
if (!involvesBCPublicKey || secretKey.getEncoded()[0] != 0)
return secretKey;
for (int retry = 0; retry < 9; retry++) {
// Regenerate the random key due to a bug/feature in BC:
// https://github.com/aws/aws-sdk-android/issues/15
secretKey = generator.generateKey();
if (secretKey.getEncoded()[0] != 0)
return secretKey;
}
// The probability of getting here is 2^80, which is impossible in practice.
throw new SdkClientException("Failed to generate secret key");
} catch (NoSuchAlgorithmException e) {
throw new SdkClientException(
"Unable to generate envelope symmetric key:"
+ e.getMessage(), e);
}
}