Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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 :
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
Hello,
Where did you put your java code ?
in a tJava component ?
In a Routine ?
Kind regards
Denis
Denis
Hi Denis,
The code is in a tJavaRow component.
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