本文整理匯總了Java中java.security.Security.getProvider方法的典型用法代碼示例。如果您正苦於以下問題:Java Security.getProvider方法的具體用法?Java Security.getProvider怎麽用?Java Security.getProvider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.Security
的用法示例。
在下文中一共展示了Security.getProvider方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import java.security.Security; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Provider provider = Security.getProvider("SunJCE");
KeyGenerator kg;
kg = KeyGenerator.getInstance("SunTlsRsaPremasterSecret", provider);
try {
kg.generateKey();
throw new Exception("no exception");
} catch (IllegalStateException e) {
System.out.println("OK: " + e);
}
int[] protocolVersions = {0x0300, 0x0301, 0x0302, 0x0400};
for (int clientVersion : protocolVersions) {
for (int serverVersion : protocolVersions) {
test(kg, clientVersion, serverVersion);
if (serverVersion >= clientVersion) {
break;
}
}
}
System.out.println("Done.");
}
示例2: verifySignature
import java.security.Security; //導入方法依賴的package包/類
public static boolean verifySignature(CMSSignedData cmsSignedData, X509Certificate cert) {
try {
if (Security.getProvider("BC") == null)
Security.addProvider(new BouncyCastleProvider());
Collection<SignerInformation> signers = cmsSignedData.getSignerInfos().getSigners();
X509CertificateHolder ch = new X509CertificateHolder(cert.getEncoded());
for (SignerInformation si : signers)
if (si.getSID().match(ch))
if (si.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(ch)))
return true;
} catch (Exception e) {}
return false;
}
示例3: main
import java.security.Security; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Provider p = Security.getProvider("SunJCE");
for (String alg : ALGORITHMS) {
for (int keyStrength : KEY_STRENGTHS) {
if (keyStrength > Cipher.getMaxAllowedKeyLength(alg)) {
// skip this if this key length is larger than what's
// configured in the JCE jurisdiction policy files
continue;
}
for (int textLength : TEXT_LENGTHS) {
for (int AADLength : AAD_LENGTHS) {
Encrypt test = new Encrypt(p, alg,
"GCM", "NoPadding", keyStrength, textLength,
AADLength);
Cipher cipher = test.createCipher(Cipher.ENCRYPT_MODE,
null);
AlgorithmParameters params = cipher.getParameters();
test.doTest(params);
System.out.println("Test " + alg + ":"
+ keyStrength + ":" + textLength + ":"
+ AADLength + " passed");
}
}
}
}
}
示例4: testInvalidPrivateKey
import java.security.Security; //導入方法依賴的package包/類
@Test(expected = IllegalArgumentException.class)
public void testInvalidPrivateKey() throws Exception {
new ECKey(
Security.getProvider("SunEC"),
KeyPairGenerator.getInstance("RSA").generateKeyPair().getPrivate(),
ECKey.fromPublicOnly(pubKey).getPubKeyPoint());
fail("Expecting an IllegalArgumentException for using an non EC private key");
}
示例5: addProvider
import java.security.Security; //導入方法依賴的package包/類
/**
* 添加簽名,驗簽,加密算法提供者
*/
private static void addProvider(){
if (Security.getProvider("BC") == null) {
log.info("add BC provider");
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
} else {
Security.removeProvider("BC"); //解決eclipse調試時tomcat自動重新加載時,BC存在不明原因異常的問題。
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
log.info("re-add BC provider");
}
printSysInfo();
}
示例6: getProvider
import java.security.Security; //導入方法依賴的package包/類
static Provider getProvider(String provider)
throws NoSuchProviderException
{
Provider prov = Security.getProvider(provider);
if (prov == null)
{
throw new NoSuchProviderException("Provider " + provider + " not found");
}
return prov;
}
示例7: publicToExplicitParameters
import java.security.Security; //導入方法依賴的package包/類
/**
* Convert a passed in public EC key to have explicit parameters. If the key
* is already using explicit parameters it is returned.
*
* @param key key to be converted
* @param providerName provider name to be used.
* @return the equivalent key with explicit curve parameters
* @throws IllegalArgumentException
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
*/
public static PublicKey publicToExplicitParameters(PublicKey key, String providerName)
throws IllegalArgumentException, NoSuchAlgorithmException, NoSuchProviderException
{
Provider provider = Security.getProvider(providerName);
if (provider == null)
{
throw new NoSuchProviderException("cannot find provider: " + providerName);
}
return publicToExplicitParameters(key, provider);
}
示例8: main
import java.security.Security; //導入方法依賴的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....");
}
}
示例9: testProviderInstallationAtRuntime
import java.security.Security; //導入方法依賴的package包/類
@BeforeClass
public static void testProviderInstallationAtRuntime() {
/* install wolfJCE provider at runtime */
Security.addProvider(new WolfCryptProvider());
Provider p = Security.getProvider("wolfJCE");
assertNotNull(p);
}
示例10: if
import java.security.Security; //導入方法依賴的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. The specified provider
* must be registered in the security provider list.
*
* <p>Note that the list of registered providers may be retrieved via
* the {@link Security#getProviders() Security.getProviders()} method.
*
* @param algorithm the URI of the algorithm
* @param mechanismType the type of the XML processing mechanism and
* representation
* @param provider the string name of the provider
* @return a new <code>TransformService</code>
* @throws NoSuchProviderException if the specified provider is not
* registered in the security provider list
* @throws NullPointerException if <code>provider</code>,
* <code>mechanismType</code>, or <code>algorithm</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 provider
* @see Provider
*/
public static TransformService getInstance
(String algorithm, String mechanismType, String provider)
throws NoSuchAlgorithmException, NoSuchProviderException {
if (mechanismType == null || algorithm == null || provider == null) {
throw new NullPointerException();
} else if (provider.length() == 0) {
throw new NoSuchProviderException();
}
boolean dom = false;
if (mechanismType.equals("DOM")) {
dom = true;
}
Provider p = Security.getProvider(provider);
if (p == null) {
throw new NoSuchProviderException("No such provider: " +
provider);
}
Service s = p.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 = p;
return ts;
}
}
}
throw new NoSuchAlgorithmException
(algorithm + " algorithm and " + mechanismType
+ " mechanism not available from " + provider);
}
示例11: testSunECRoundTrip
import java.security.Security; //導入方法依賴的package包/類
@Test
public void testSunECRoundTrip() throws Exception {
Provider provider = Security.getProvider("SunEC");
if (provider != null) {
testProviderRoundTrip(provider);
} else {
System.out.println("Skip test as provider doesn't exist. Must be OpenJDK 1.7 which ships without 'SunEC'");
}
}
示例12: setup
import java.security.Security; //導入方法依賴的package包/類
/**
* Ensure that BouncyCastleProvider is registered.
*/
@BeforeClass
public static void setup() {
if (Security.getProvider("BC") == null) {
Security.addProvider(new BouncyCastleProvider());
}
}
示例13: calculateHASH
import java.security.Security; //導入方法依賴的package包/類
public static byte[] calculateHASH(String digestOID, byte[] data) throws Exception{
String digestName = "";
try{
if(Security.getProvider("BC") == null)
Security.addProvider(new BouncyCastleProvider());
if(digestOID.equals(CMSSignedDataGenerator.DIGEST_MD5))
digestName = "MD5";
if(digestOID.equals(CMSSignedDataGenerator.DIGEST_SHA1))
digestName = "SHA-1";
if(digestOID.equals(CMSSignedDataGenerator.DIGEST_SHA256))
digestName = "SHA-256";
if(digestOID.equals(CMSSignedDataGenerator.DIGEST_SHA384))
digestName = "SHA-384";
if(digestOID.equals(CMSSignedDataGenerator.DIGEST_SHA512))
digestName = "SHA-512";
if(digestName.equals(""))
throw new Exception("Unsupported digestOID");
MessageDigest md = MessageDigest.getInstance(digestName, "BC");
md.update(data);
byte[] hash = md.digest();
return hash;
}catch(Exception e){
throw new Exception("Error on the generation for the Hash "+digestName+":\n"+e.getMessage());
}
}
示例14: main
import java.security.Security; //導入方法依賴的package包/類
public static void main(String[] args) {
TestCipherPBECons test = new TestCipherPBECons();
Provider sunjce = Security.getProvider("SunJCE");
if (!test.runAll(sunjce, System.out)) {
throw new RuntimeException("One or more tests have failed....");
}
}
示例15: verifyAllSignatures
import java.security.Security; //導入方法依賴的package包/類
public static boolean verifyAllSignatures(CMSSignedData cmsSignedData) {
try {
if (Security.getProvider("BC") == null)
Security.addProvider(new BouncyCastleProvider());
Collection<SignerInformation> signers = cmsSignedData.getSignerInfos().getSigners();
for (SignerInformation si : signers) {
@SuppressWarnings("unchecked")
Collection<X509CertificateHolder> certList = cmsSignedData.getCertificates().getMatches(si.getSID());
if (certList.size() == 0)
throw new Exception("ERROR: Impossible to find a Certificate using the Signer ID: " + si.getSID());
X509CertificateHolder cert = certList.iterator().next(); // Take only the first certificate of the chain
if (!si.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert)))
throw new Exception("ATTENTION: At least a signature is invalid!");
boolean certOK = true;
String msg = "";
try {
X509Utils.checkAllOnCertificate(X509Utils.getX509Certificate(cert.getEncoded()));
} catch (Exception ex) {
msg = ex.getMessage();
certOK = false;
}
if (!certOK)
throw new Exception("ATTENTION: The certificate is invalid:\n" + msg);
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}