Forum Discussion
How to RSA-OAEP encrypt credentials using Node js (not c# or PowerShell)
- 4 years ago
In case this helps anyone seekeing a solution for the sale problem, here's what I did.
I used a PowerShell script as described here https://endjin.com/blog/2020/12/how-to-update-credentials-for-an-on-prem-power-bi-data-source-using-powershell.html then executed ith with Node, retrieving the resulting JSON. The Node code looks like this
```javascript const { exec } = require('child_process'); const PShellScriptFile = './rsa-oeap-encrypt-credentials.ps1' const datasourceCredentialsEncryptedFile = "./datasourceCredentialsEncryptedFile.json" var username = "useNameHere" var password = "passwordHere" // WARNING. Gateway module is fixed and should go as param exec(`${PShellScriptFile} -username ${username} -password ${password} -outputFile ${datasourceCredentialsEncryptedFile}`, {'shell':'powershell.exe'}, (error, stdout, stderr)=> { // you can use stdout but I choose getting the JSON file already generated by the script }) ```The outcome looks like this
{ "credentialDetails": { "encryptedConnection": "Encrypted", "credentialType": "Basic", "credentials": "oCvURzaedv3WNvV...lRQZ", "privacyLevel": "Private", "encryptionAlgorithm": "RSA-OAEP" } }Which you can then use in Gateways - Create Datasource - REST API (Power BI Power BI REST APIs) | Microsoft Docs
In case this helps anyone seekeing a solution for the sale problem, here's what I did.
I used a PowerShell script as described here https://endjin.com/blog/2020/12/how-to-update-credentials-for-an-on-prem-power-bi-data-source-using-powershell.html then executed ith with Node, retrieving the resulting JSON. The Node code looks like this
```javascript
const { exec } = require('child_process');
const PShellScriptFile = './rsa-oeap-encrypt-credentials.ps1'
const datasourceCredentialsEncryptedFile = "./datasourceCredentialsEncryptedFile.json"
var username = "useNameHere"
var password = "passwordHere"
// WARNING. Gateway module is fixed and should go as param
exec(`${PShellScriptFile} -username ${username} -password ${password} -outputFile ${datasourceCredentialsEncryptedFile}`, {'shell':'powershell.exe'}, (error, stdout, stderr)=> {
// you can use stdout but I choose getting the JSON file already generated by the script
})
```The outcome looks like this
{
"credentialDetails": {
"encryptedConnection": "Encrypted",
"credentialType": "Basic",
"credentials": "oCvURzaedv3WNvV...lRQZ",
"privacyLevel": "Private",
"encryptionAlgorithm": "RSA-OAEP"
}
}Which you can then use in Gateways - Create Datasource - REST API (Power BI Power BI REST APIs) | Microsoft Docs