Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
PR_GirardeauLaurent
Contributor
Contributor

Error message when decrypting Private Key for SnowFlake : java.lang.NoClassDefFoundError: org/bouncycastle/openssl/PEMParser

Hi All,

I am currently trying to retrieve an encrypted private key for SnowFlake from Azure Key Vault.

I have build all the components needed to retrieve the key from AKV but now I am facing an issue while reading the key. (i have follow the instruction here Qlik Talend key pair authentication with Snowflake via Azure Key Vault | by Archan Chatterjee | Medi..., which were great)

Because it is encrypted with a non natively supported encryption from OpenSSL, I need to decrypt it before sending it to my Keystore using BouncyCastle.

My code in error is the following :

Security.addProvider(new BouncyCastleProvider());

//Restaurer le format PEM complet (header/footer + lignes normales)
String pemFormattedPrivateKey = "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
+ base64PrivateKey.replaceAll("(.{64})", "$1\n") + "\n"
+ "-----END ENCRYPTED PRIVATE KEY-----";

//Utiliser PEMParser pour parser la clé
PEMParser pemParser = new PEMParser(new StringReader(pemFormattedPrivateKey));
Object parsedObject = pemParser.readObject();
pemParser.close();

PKCS8EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = (PKCS8EncryptedPrivateKeyInfo) parsedObject;
InputDecryptorProvider decryptorProvider = new JceOpenSSLPKCS8DecryptorProviderBuilder().build(password);

PrivateKeyInfo privateKeyInfo = encryptedPrivateKeyInfo.decryptPrivateKeyInfo(decryptorProvider);
PrivateKey privateKey = new JcaPEMKeyConverter()
.setProvider("BC")
.getPrivateKey(privateKeyInfo);

What Studio seems to doesn't like is this line :

PEMParser pemParser = new PEMParser(new StringReader(pemFormattedPrivateKey));

The error is :

Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/openssl/PEMParser
at leap_datamig.snowflake_connection_test_0_1.Snowflake_Connection_test.tRESTClient_1Process(Snowflake_Connection_test.java:5249)
at leap_datamig.snowflake_connection_test_0_1.Snowflake_Connection_test.runJobInTOS(Snowflake_Connection_test.java:6668)
at leap_datamig.snowflake_connection_test_0_1.Snowflake_Connection_test.main(Snowflake_Connection_test.java:6142)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.openssl.PEMParser
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
 
I have done everything requiered:
Added the requiered librairies:
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.openssl.PEMParser;
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
import org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8DecryptorProviderBuilder;
import org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo;
import org.bouncycastle.operator.InputDecryptorProvider;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.io.StringReader;
import java.security.Security;

Updated the Maven Project :

<dependencies>
<!-- Base cryptographic provider -->
<dependency>
  <groupId>org.bouncycastle</groupId>
  <artifactId>bcprov-jdk18on</artifactId>
  <version>1.78.1</version>
</dependency>

<!-- Extensions for PEM/PKIX (needed for PEMParser) -->
<dependency>
  <groupId>org.bouncycastle</groupId>
  <artifactId>bcpkix-jdk18on</artifactId>
  <version>1.78.1</version>
</dependency>
</dependencies>

Checked if the Jar are in the Module section (all ok).

But nothing worked.

Do you have any idea what could be the issue ?

Thanks

Labels (3)
3 Replies
Denis_Segard
Support
Support

Hello,

Where did you put your java code ?
in a tJava component ? 
In a Routine ?

 

Kind regards
Denis

Denis

PR_GirardeauLaurent
Contributor
Contributor
Author

Hi Denis,

The code is in a tJavaRow component.

Denis_Segard
Support
Support

Hello Laurent,
Did you test to add a tLibraryLoad (or several) in order to "load" the librarie(s) (jar file(s)) containing the Java classes used in the tJavaRow ? 

Kind regards
Denis