简体   繁体   English

没有这样的算法:AES/GCM/NoPadding

[英]No Such Algorithm : AES/GCM/NoPadding

I'm trying to use AES/GCM/NoPadding within the Java code for decryption.我正在尝试在 Java 代码中使用 AES/GCM/NoPadding 进行解密。 Below is the code下面是代码

public static byte[] decryptRes(final byte[] sessionKey, final String symetricKeyAlg,
        final String pkiProvider, final String encXML, final String msgRefNo)
        throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException,
        BadPaddingException, NoSuchProviderException, InvalidAlgorithmParameterException {
    Security.addProvider(new BouncyCastleProvider());
    final StringBuilder strBuilder = new StringBuilder(msgRefNo);
    strBuilder.append("0000");
    final SecretKeySpec symmKeySpec = new SecretKeySpec(sessionKey, "AES");
    final Cipher symmCipher = Cipher.getInstance("AES/GCM/NoPadding", "BC");
    symmCipher.init(2, symmKeySpec, new IvParameterSpec(strBuilder.toString().getBytes()));
    final byte[] xmlData = symmCipher.doFinal(base64Decode(encXML));
    return xmlData;
}

Now, when this code is invoked, it throws现在,当调用此代码时,它会抛出

Exception: java.security.NoSuchAlgorithmException: No such algorithm: AES/GCM/NoPadding异常:java.security.NoSuchAlgorithmException:没有这样的算法:AES/GCM/NoPadding

and not并不是

NoSuchProviderException. NoSuchProviderException。

The necessary providers is already added but I still get the above mentioned exception.已经添加了必要的提供程序,但我仍然遇到上述异常。

Java version 7 being used. Java 正在使用版本 7。

Jars Used: Jars 使用:

  1. bcprov-jdk15to18-169.jar bcprov-jdk15to18-169.jar

  2. bcprov-ext-jdk15to18-169.jar bcprov-ext-jdk15to18-169.jar

The above jars are available in the application lib folder.以上jars在应用程序lib文件夹中可用。

I could finally resolve the above mentioned issue.我终于可以解决上述问题。 There is absolutely no issue with the code provided.提供的代码绝对没有问题。 However, I was facing the issue because of the BouncyCastle jar not registered as Service Provider.但是,由于 BouncyCastle jar 未注册为服务提供商,我遇到了这个问题。 Updated the java.security file under更新了java.security文件

>$JAVAHOME/lib/security/java.security >$JAVAHOME/lib/security/java.security

Add the below line if the provided is not added如果未添加提供的,请添加以下行

security.provider.<#>=org.bouncycastle.jce.provider.BouncyCastleProvider security.provider.<#>=org.bouncycastle.jce.provider.BouncyCastleProvider

Follow the link for details :点击链接了解详情

https://makeinjava.com/install-bouncy-castle-provider-configuring-java-runtime-example/ https://makeinjava.com/install-bouncy-castle-provider-configuring-java-runtime-example/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AES / GCM / NoPadding AEADBadTagException - AES/GCM/NoPadding AEADBadTagException 将 Java AES/GCM/NoPadding 算法转换为 C# - Convert Java AES/GCM/NoPadding algorithm to C# 没有安装的提供程序支持这个密钥:sun.security.rsa.RSAPublicKeyImpl 并且没有这样的算法:AES/GCM/NoPadding - No installed provider supports this key: sun.security.rsa.RSAPublicKeyImpl and No such algorithm: AES/GCM/NoPadding 在节点 js 中通过 AES/GCM/NoPadding 算法使用密钥和 iv 加密有效负载并在 java 中解密 - Encrypt payload using a key and iv by AES/GCM/NoPadding algorithm in node js and decrypt in java 使用AES / GCM / NoPadding的IvParameterSpec和GCMParameterSpec之间的差异 - Difference between IvParameterSpec and GCMParameterSpec with AES/GCM/NoPadding AES/GCM/NoPadding加密JAVA&解密JavaScript - AES/GCM/NoPadding encryption in JAVA & decryption in JavaScript JS 中 Java 的 AES/GCM/NoPadding 等价物 - Java's AES/GCM/NoPadding equivalent in JS javax.crypto.AEADBadTagException - AES / GCM / NoPadding工作,然后没有 - javax.crypto.AEADBadTagException - AES/GCM/NoPadding works, then doesn't 错误解密在Android中使用AES / GCM / NoPadding加密的消息 - Error decrypting message encrypted using AES/GCM/NoPadding in Android Java AES / GCM / NoPadding - 什么是cipher.getIV()给我的? - Java AES/GCM/NoPadding - What is cipher.getIV() giving me?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM