Generate a Java Keystore file from the JSON private key file
- UpdatedAug 3, 2023
- 2 minutes to read
- Vancouver
- Virtual Agent
To use Google Dialogflow with Virtual Agent Bot Interconnect, the third step is to generate a JKS file from the JSON private key you created in the previous step.
Before you begin
Role required: admin
Procedure
- In a text editor, open the JSON private key file you downloaded in the previous procedure.
-
Copy the private key text, starting with the BEGIN PRIVATE KEY section and
ending with the END PRIVATE KEY section.
-
Remove the line return characters (\n) from the key:
- Paste the key text in a text editor, such as TextEdit or Notepad.
- Click Edit > Find > Find & Replace or Edit > Replace.
- In the Find field, type \n.
- In the Replace field, press Ctrl + Enter or Alt + Enter.
- Click Replace All.
The key text will be formatted with line breaks. -
Save the formatted private key text as a .pem file.
For example, privatekey.pem.
-
In a web browser, open the URL that is listed in the JSON file for
the client_x509_cert_url parameter.
For example, https://www.googleapis.com/robot/v1/metadata/x509/my-srvc-account%40my-agent-ukpy.iam.gserviceaccount.com. The certificates page opens.
- Copy the certificate that has the same private key ID that appears in the JSON file.
- Replace \n with line breaks in the certificate, as described in step 3.
-
Save the formatted certificate as a .pem file.
For example, certificate.pem.
- Navigate to the folder that contains both the private key and certificate files.
-
Open a terminal window:
- In Mac OS, right-click or ctrl-click the folder and select New terminal at folder.
- In Windows, right-click the folder and select Open in terminal.
-
At the terminal's command prompt, create the JKS file as follows:
-
Enter the following command:
openssl pkcs12 -export -in [certificate file name] -inkey [private key file name] -certfile [certificate file name] -out testkeystore.p12
For example, if certificate.pem is the name of the certficate and privatekey.pem is the name of the private key:
openssl pkcs12 -export -in certificate.pem -inkey privatekey.pem -certfile certificate.pem -out testkeystore.p12
-
When prompted for a password, enter the password of your choice using a
minimum of six characters.
A PKCS 12 file is created with the name testkeystore.p12.
-
Enter the following command:
keytool -importkeystore -srckeystore testkeystore.p12 -srcstoretype pkcs12 -destkeystore dialogflow.jks -deststoretype JKS
You will be prompted for a password multiple times. Use the same password you created in the previous step.
-
Enter the following command:
Result