我正在做一个需要安装“Java Cryptography Extension”(JCE)的项目,我认为我已经完成了。我按照这里的说明进行操作:
http://suhothayan.blogspot.com/2012/05/how-to-install-java-cryptography.html
有什么方法可以验证我是否已正确安装它 - 我正在运行的一些测试表明它不是。
原来我的问题是以下问题的重复,并且接受的解决方案非常有效:
我正在做一个需要安装“Java Cryptography Extension”(JCE)的项目,我认为我已经完成了。我按照这里的说明进行操作:
http://suhothayan.blogspot.com/2012/05/how-to-install-java-cryptography.html
有什么方法可以验证我是否已正确安装它 - 我正在运行的一些测试表明它不是。
原来我的问题是以下问题的重复,并且接受的解决方案非常有效:
import java.security.Provider;
import java.security.Security;
import java.util.Arrays;
public class ShowCryptoProviders
{
private static final String EOL = System.getProperty("line.separator");
public static void main(final String[] args)
{
final Provider[] providers = Security.getProviders();
final Boolean verbose = Arrays.asList(args).contains("-v");
for (final Provider p : providers)
{
System.out.format("%s %s%s", p.getName(), p.getVersion(), EOL);
for (final Object o : p.keySet())
{
if (verbose)
{
System.out.format("\t%s : %s%s", o, p.getProperty((String)o), EOL);
}
}
}
}
}
我无法想象这里的某些东西不能告诉你你需要知道什么。如果它不只是通过检查来测试“无限强度”Cypher.getMaxAllowedKeyLength()
,它应该返回一个远高于 128 的非常大的数字。
使用-v
(verbose) 获得以下输出。
SunJCE 1.7
Cipher.Blowfish SupportedKeyFormats : RAW
AlgorithmParameters.DESede : com.sun.crypto.provider.DESedeParameters
AlgorithmParameters.DES : com.sun.crypto.provider.DESParameters
Cipher.DES SupportedPaddings : NOPADDING|PKCS5PADDING|ISO10126PADDING
AlgorithmParameters.Blowfish : com.sun.crypto.provider.BlowfishParameters
Cipher.DESedeWrap SupportedKeyFormats : RAW
Alg.Alias.KeyAgreement.1.2.840.113549.1.3.1 : DiffieHellman
AlgorithmParameterGenerator.DiffieHellman : com.sun.crypto.provider.DHParameterGenerator
Cipher.RSA SupportedPaddings : NOPADDING|PKCS1PADDING|OAEPWITHMD5ANDMGF1PADDING|OAEPWITHSHA1ANDMGF1PADDING|OAEPWITHSHA-1ANDMGF1PADDING|OAEPWITHSHA-256ANDMGF1PADDING|OAEPWITHSHA-384ANDMGF1PADDING|OAEPWITHSHA-512ANDMGF1PADDING
Alg.Alias.Cipher.TripleDES : DESede
Cipher.ARCFOUR SupportedModes : ECB
Mac.SslMacSHA1 SupportedKeyFormats : RAW
KeyGenerator.DES : com.sun.crypto.provider.DESKeyGenerator
Provider.id version : 1.7
KeyGenerator.DESede : com.sun.crypto.provider.DESedeKeyGenerator
Alg.Alias.SecretKeyFactory.PBE : PBEWithMD5AndDES
Alg.Alias.KeyFactory.1.2.840.113549.1.3.1 : DiffieHellman
Mac.HmacSHA1 : com.sun.crypto.provider.HmacSHA1
Cipher.PBEWithMD5AndDES : com.sun.crypto.provider.PBEWithMD5AndDESCipher
Cipher.AES SupportedModes : ECB|CBC|PCBC|CTR|CTS|CFB|OFB|CFB8|CFB16|CFB24|CFB32|CFB40|CFB48|CFB56|CFB64|OFB8|OFB16|OFB24|OFB32|OFB40|OFB48|OFB56|OFB64|CFB72|CFB80|CFB88|CFB96|CFB104|CFB112|CFB120|CFB128|OFB72|OFB80|OFB88|OFB96|OFB104|OFB112|OFB120|OFB128
Cipher.AESWrap SupportedModes : ECB
SecretKeyFactory.DESede : com.sun.crypto.provider.DESedeKeyFactory
KeyGenerator.SunTlsKeyMaterial : com.sun.crypto.provider.TlsKeyMaterialGenerator
AlgorithmParameters.OAEP : com.sun.crypto.provider.OAEPParameters
Cipher.AES SupportedKeyFormats : RAW
AlgorithmParameters.RC2 : com.sun.crypto.provider.RC2Parameters
AlgorithmParameters.PBE : com.sun.crypto.provider.PBEParameters
Alg.Alias.KeyPairGenerator.DH : DiffieHellman
Alg.Alias.KeyAgreement.OID.1.2.840.113549.1.3.1 : DiffieHellman
Cipher.AES : com.sun.crypto.provider.AESCipher
KeyGenerator.RC2 : com.sun.crypto.provider.KeyGeneratorCore$RC2KeyGenerator
Mac.HmacSHA512 : com.sun.crypto.provider.HmacCore$HmacSHA512
Provider.id info : SunJCE Provider (implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, Diffie-Hellman, HMAC)
Cipher.AES SupportedPaddings : NOPADDING|PKCS5PADDING|ISO10126PADDING
Alg.Alias.AlgorithmParameters.OID.1.2.840.113549.1.12.1.6 : PBEWithSHA1AndRC2_40
Cipher.Blowfish SupportedPaddings : NOPADDING|PKCS5PADDING|ISO10126PADDING
Alg.Alias.AlgorithmParameters.OID.1.2.840.113549.1.12.1.3 : PBEWithSHA1AndDESede
Alg.Alias.KeyGenerator.SunTls12KeyMaterial : SunTlsKeyMaterial
KeyStore.JCEKS : com.sun.crypto.provider.JceKeyStore
Cipher.Blowfish SupportedModes : ECB|CBC|PCBC|CTR|CTS|CFB|OFB|CFB8|CFB16|CFB24|CFB32|CFB40|CFB48|CFB56|CFB64|OFB8|OFB16|OFB24|OFB32|OFB40|OFB48|OFB56|OFB64
Alg.Alias.SecretKeyFactory.1.2.840.113549.1.5.12 : PBKDF2WithHmacSHA1
Mac.HmacSHA384 SupportedKeyFormats : RAW
Cipher.DESedeWrap : com.sun.crypto.provider.DESedeWrapCipher
Cipher.ARCFOUR SupportedPaddings : NOPADDING
Alg.Alias.KeyPairGenerator.1.2.840.113549.1.3.1 : DiffieHellman
Cipher.PBEWithMD5AndTripleDES : com.sun.crypto.provider.PBEWithMD5AndTripleDESCipher
Alg.Alias.Cipher.1.2.840.113549.1.12.1.6 : PBEWithSHA1AndRC2_40
Alg.Alias.Cipher.1.2.840.113549.1.12.1.3 : PBEWithSHA1AndDESede
Mac.HmacSHA256 SupportedKeyFormats : RAW
Alg.Alias.KeyGenerator.SunTls12RsaPremasterSecret : SunTlsRsaPremasterSecret
Alg.Alias.AlgorithmParameterGenerator.1.2.840.113549.1.3.1 : DiffieHellman
Cipher.PBEWithSHA1AndDESede : com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndDESede
Alg.Alias.KeyGenerator.SunTls12MasterSecret : SunTlsMasterSecret
SecretKeyFactory.PBEWithMD5AndDES : com.sun.crypto.provider.PBEKeyFactory$PBEWithMD5AndDES
KeyPairGenerator.DiffieHellman : com.sun.crypto.provider.DHKeyPairGenerator
Cipher.RC2 SupportedModes : ECB|CBC|PCBC|CTR|CTS|CFB|OFB|CFB8|CFB16|CFB24|CFB32|CFB40|CFB48|CFB56|CFB64|OFB8|OFB16|OFB24|OFB32|OFB40|OFB48|OFB56|OFB64
Alg.Alias.AlgorithmParameters.Rijndael : AES
KeyAgreement.DiffieHellman SupportedKeyClasses : javax.crypto.interfaces.DHPublicKey|javax.crypto.interfaces.DHPrivateKey
Mac.HmacMD5 SupportedKeyFormats : RAW
KeyGenerator.SunTlsRsaPremasterSecret : com.sun.crypto.provider.TlsRsaPremasterSecretGenerator
Cipher.AESWrap SupportedKeyFormats : RAW
SecretKeyFactory.DES : com.sun.crypto.provider.DESKeyFactory
Cipher.AESWrap SupportedPaddings : NOPADDING
Provider.id name : SunJCE
KeyGenerator.HmacSHA512 : com.sun.crypto.provider.KeyGeneratorCore$HmacSHA512KG
Mac.HmacSHA256 : com.sun.crypto.provider.HmacCore$HmacSHA256
Cipher.ARCFOUR SupportedKeyFormats : RAW
Cipher.DES SupportedModes : ECB|CBC|PCBC|CTR|CTS|CFB|OFB|CFB8|CFB16|CFB24|CFB32|CFB40|CFB48|CFB56|CFB64|OFB8|OFB16|OFB24|OFB32|OFB40|OFB48|OFB56|OFB64
Cipher.RSA SupportedKeyClasses : java.security.interfaces.RSAPublicKey|java.security.interfaces.RSAPrivateKey
SecretKeyFactory.PBEWithMD5AndTripleDES : com.sun.crypto.provider.PBEKeyFactory$PBEWithMD5AndTripleDES
Cipher.PBEWithSHA1AndRC2_40 : com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndRC2_40
AlgorithmParameters.DiffieHellman : com.sun.crypto.provider.DHParameters
Mac.HmacMD5 : com.sun.crypto.provider.HmacMD5
Cipher.RSA : com.sun.crypto.provider.RSACipher
Mac.SslMacMD5 : com.sun.crypto.provider.SslMacCore$SslMacMD5
Alg.Alias.AlgorithmParameters.OID.1.2.840.113549.1.5.3 : PBEWithMD5AndDES
Cipher.DESede SupportedPaddings : NOPADDING|PKCS5PADDING|ISO10126PADDING
Alg.Alias.AlgorithmParameterGenerator.OID.1.2.840.113549.1.3.1 : DiffieHellman
Cipher.DESede : com.sun.crypto.provider.DESedeCipher
Alg.Alias.AlgorithmParameters.OID.1.2.840.113549.1.3.1 : DiffieHellman
Alg.Alias.AlgorithmParameters.1.2.840.113549.1.5.3 : PBEWithMD5AndDES
Mac.HmacSHA512 SupportedKeyFormats : RAW
Mac.HmacPBESHA1 SupportedKeyFormats : RAW
Alg.Alias.AlgorithmParameterGenerator.DH : DiffieHellman
Cipher.DESedeWrap SupportedPaddings : NOPADDING
Alg.Alias.SecretKeyFactory.OID.1.2.840.113549.1.5.12 : PBKDF2WithHmacSHA1
Alg.Alias.AlgorithmParameters.1.2.840.113549.1.3.1 : DiffieHellman
Mac.HmacPBESHA1 : com.sun.crypto.provider.HmacPKCS12PBESHA1
Cipher.DES SupportedKeyFormats : RAW
AlgorithmParameters.PBEWithMD5AndTripleDES : com.sun.crypto.provider.PBEParameters
Cipher.DESedeWrap SupportedModes : CBC
Alg.Alias.KeyFactory.OID.1.2.840.113549.1.3.1 : DiffieHellman
Alg.Alias.Cipher.OID.1.2.840.113549.1.5.3 : PBEWithMD5AndDES
AlgorithmParameters.AES : com.sun.crypto.provider.AESParameters
Alg.Alias.AlgorithmParameters.TripleDES : DESede
Alg.Alias.SecretKeyFactory.TripleDES : DESede
KeyGenerator.HmacSHA256 : com.sun.crypto.provider.KeyGeneratorCore$HmacSHA256KG
Alg.Alias.KeyGenerator.TripleDES : DESede
Alg.Alias.AlgorithmParameters.DH : DiffieHellman
KeyGenerator.AES : com.sun.crypto.provider.AESKeyGenerator
Cipher.RC2 SupportedPaddings : NOPADDING|PKCS5PADDING|ISO10126PADDING
Alg.Alias.Cipher.RC4 : ARCFOUR
Alg.Alias.KeyPairGenerator.OID.1.2.840.113549.1.3.1 : DiffieHellman
Mac.HmacSHA384 : com.sun.crypto.provider.HmacCore$HmacSHA384
SecretKeyFactory.PBKDF2WithHmacSHA1 : com.sun.crypto.provider.PBKDF2HmacSHA1Factory
Provider.id className : com.sun.crypto.provider.SunJCE
Cipher.DES : com.sun.crypto.provider.DESCipher
Cipher.Blowfish : com.sun.crypto.provider.BlowfishCipher
KeyGenerator.SunTlsMasterSecret : com.sun.crypto.provider.TlsMasterSecretGenerator
KeyGenerator.HmacSHA1 : com.sun.crypto.provider.HmacSHA1KeyGenerator
Alg.Alias.SecretKeyFactory.1.2.840.113549.1.5.3 : PBEWithMD5AndDES
KeyGenerator.SunTlsPrf : com.sun.crypto.provider.TlsPrfGenerator$V10
SecretKeyFactory.PBEWithSHA1AndDESede : com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndDESede
KeyGenerator.ARCFOUR : com.sun.crypto.provider.KeyGeneratorCore$ARCFOURKeyGenerator
Alg.Alias.KeyAgreement.DH : DiffieHellman
Alg.Alias.KeyGenerator.Rijndael : AES
AlgorithmParameters.PBEWithSHA1AndDESede : com.sun.crypto.provider.PBEParameters
Alg.Alias.KeyGenerator.RC4 : ARCFOUR
Alg.Alias.Cipher.OID.1.2.840.113549.1.12.1.6 : PBEWithSHA1AndRC2_40
Alg.Alias.Cipher.OID.1.2.840.113549.1.12.1.3 : PBEWithSHA1AndDESede
Mac.SslMacMD5 SupportedKeyFormats : RAW
Mac.HmacSHA1 SupportedKeyFormats : RAW
Cipher.DESede SupportedKeyFormats : RAW
Cipher.RC2 : com.sun.crypto.provider.RC2Cipher
KeyGenerator.SunTls12Prf : com.sun.crypto.provider.TlsPrfGenerator$V12
SecretKeyFactory.PBEWithSHA1AndRC2_40 : com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC2_40
KeyGenerator.HmacMD5 : com.sun.crypto.provider.HmacMD5KeyGenerator
AlgorithmParameters.PBEWithSHA1AndRC2_40 : com.sun.crypto.provider.PBEParameters
KeyGenerator.HmacSHA384 : com.sun.crypto.provider.KeyGeneratorCore$HmacSHA384KG
Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.6 : PBEWithSHA1AndRC2_40
KeyFactory.DiffieHellman : com.sun.crypto.provider.DHKeyFactory
Alg.Alias.AlgorithmParameters.1.2.840.113549.1.12.1.3 : PBEWithSHA1AndDESede
AlgorithmParameters.PBEWithMD5AndDES : com.sun.crypto.provider.PBEParameters
Alg.Alias.SecretKeyFactory.1.2.840.113549.1.12.1.6 : PBEWithSHA1AndRC2_40
Alg.Alias.SecretKeyFactory.1.2.840.113549.1.12.1.3 : PBEWithSHA1AndDESede
Cipher.AESWrap : com.sun.crypto.provider.AESWrapCipher
Alg.Alias.SecretKeyFactory.OID.1.2.840.113549.1.5.3 : PBEWithMD5AndDES
Alg.Alias.Cipher.Rijndael : AES
Cipher.RSA SupportedModes : ECB
Cipher.DESede SupportedModes : ECB|CBC|PCBC|CTR|CTS|CFB|OFB|CFB8|CFB16|CFB24|CFB32|CFB40|CFB48|CFB56|CFB64|OFB8|OFB16|OFB24|OFB32|OFB40|OFB48|OFB56|OFB64
Alg.Alias.SecretKeyFactory.OID.1.2.840.113549.1.12.1.6 : PBEWithSHA1AndRC2_40
Alg.Alias.SecretKeyFactory.OID.1.2.840.113549.1.12.1.3 : PBEWithSHA1AndDESede
Cipher.ARCFOUR : com.sun.crypto.provider.ARCFOURCipher
Alg.Alias.Cipher.1.2.840.113549.1.5.3 : PBEWithMD5AndDES
Mac.SslMacSHA1 : com.sun.crypto.provider.SslMacCore$SslMacSHA1
KeyAgreement.DiffieHellman : com.sun.crypto.provider.DHKeyAgreement
Cipher.RC2 SupportedKeyFormats : RAW
Alg.Alias.KeyFactory.DH : DiffieHellman
KeyGenerator.Blowfish : com.sun.crypto.provider.BlowfishKeyGenerator
我相信检查特定KeyGenerator.HmacSHA512 : com.sun.crypto.provider.KeyGeneratorCore$HmacSHA512KG
的密钥生成器可能会告诉您同样的事情,而不必依赖密钥长度查询。
当然,
这是一小段代码:
public static void main(final String[] args) {
final Provider[] providers = Security.getProviders();
for (int i = 0; i < providers.length; i++) {
final String name = providers[i].getName();
final double version = providers[i].getVersion();
System.out.println("Provider[" + i + "]:: " + name + " " + version);
if (args.length > 0) {
final Iterator it = providers[i].keySet().iterator();
while (it.hasNext()) {
final String element = (String) it.next();
if (element.toLowerCase().startsWith(args[0].toLowerCase())
|| args[0].equals("-all"))
System.out.println("\t" + element);
}
}
}
}
当您运行它时,您将获得所有已安装的提供程序:
这些是我的例子:
Provider[0]:: SUN 1.6
Provider[1]:: Apple 1.0
Provider[2]:: SunRsaSign 1.5
Provider[3]:: SunJSSE 1.6
Provider[4]:: SunJCE 1.6
Provider[5]:: SunJGSS 1.0
Provider[6]:: SunSASL 1.5
Provider[7]:: XMLDSig 1.0
Provider[8]:: SunPCSC 1.6
如果你需要更多,你可以通过给出“-all”参数来激活代码的内部循环。
要检查您的最大密钥长度,您可以使用:
System.out.println(Cipher.getMaxAllowedKeyLength("AES"));
如果没有无限强度策略文件,则结果为 128,正确安装后结果为 2147483647。