Power BI-创建数据源端点错误

时间:2020-07-03 16:45:01

标签: c# node.js encryption powerbi powerbi-datasource

我正在尝试使用Create Datasource REST endpoint from Microsoft's Power BI API,但是在发送Windows凭据的加密字符串时出现400错误。我的API是用nodejs编写的,因此我正在使用node-rsa在其文档中复制C#解决方案中的功能。

我使用此C#代码生成了一个加密的凭据字符串,它可以正常工作并返回201以创建数据源:

var credentials = new WindowsCredentials(username: "myusername", password: "mypassword");

var publicKey = new GatewayPublicKey("<exponent>", "<modulus>");
            
var credentialsEncryptor = new AsymmetricKeyEncryptor(publicKey);
var credentialDetails = new CredentialDetails(credentials, PrivacyLevel.Organizational, EncryptedConnection.Encrypted, credentialsEncryptor);

这是来自上述代码中oavtaHCi2Nkn0euRQxtRvZ2aDPnLA5/T1B6YHHeQzfBDXLJsU4JOx3ZOm31nEWqPRUh2DLARKI0y+C106wgOhWKgxI4nIz5jmJCQqPWRzOYlJlvdPQCOrTtuvIZb3IRy2OAhBfKOcOA8xqHIkKsqvTX1u4LUgfNuwxmU16FB/d3mzZOtc3+ld2MUp15HEPBCen6qTOkdEOwOm2AqxSidx46xoahLrqjkMtLZqLimooVGeTmuXm7bwoRQa1VKUwPaAuKcBBfAuRJulXyeSOMkwKz90pA30y8g7aB2NvT+92SzzjpuHcs1bzPrbPR1J+WXSRTN7xzlCOyQmC5YiQKn6A==AADPIC5L5rjd7WWThtCNAPunINW330ka1ts53SsBkaelIrZ8f9msgE4JjliaeDM91Qq3KDqm1DUjLw6Fg92LzZhMkjcwdEBued/piCdvIpP0eA9rhX0kjWWaMzQF6T3fHr798OkL7yMPEGi+m7Z3cOz22HP2Ot1ORxf6RH/JUNJmLEepEYCRVVubmKL04IyEtx8dShtSG+upeOaBOaD/GOS5

的credentialDetails对象的Credentials属性的加密字符串。

这是我使用node-rsa的nodejs解决方案。无法理解为什么上面的C#代码中的加密字符串有效,但是这个无效。

const nodersa = require('node-rsa');

const credentials =
    '{"credentialData":[{"name":"username", "value":"myusername"},{"name":"password", "value":"mypassword"}]}';

const exponentString = '<exponent>';
const modulusString = '<modulus>';

const key = new nodersa();

key.setOptions({
    encryptionScheme: 'pkcs1_oaep',
});

const pubKey = key.importKey({
    n: Buffer.from(modulusString, 'base64'),
    e: Buffer.from(exponentString, 'base64'),
});

const encrypted = pubKey.encrypt(credentials, 'base64');

这是上面这段代码中的加密字符串:UCLIIGF8u6HMdlLAwVeZcM0iLks5YLEWhRfpywnNBrAdSoPlP8/vRqe4knMCnAFiSimHiX8fu/CQlAP0b98Xlzx6sHnW4sQHV5KgUErLQfBP5i+5LGj7lBDB0/nsuf2hLDSrXXUb3F+XXv1mlUTgNZzwanizUuRcqYRxcdMaYOjI1vCaQbW++kHXMgOQPjMBj8hrJ1gW1WznS3zCYy6v8oUwEzJtp2aQEP8Pycvx5KwjVdy9KxkB675+TfddauMlz0B+EpQjC1Z+k87uiuFpGZxwA5FAi+4r8ztZ+9/su+8eieCSBK/8ZokAUNcrLmU0sPuDewaojW1MBdxvJiv7YA==


这是Power BI API使用通过节点解决方案加密的字符串返回的错误。关于我的请求的所有其他信息都是相同的,除了加密凭据之外,因此我相信这就是问题所在。

{
  "error": {
    "code": "DM_GWPipeline_UnknownError",
    "pbi.error": {
      "code": "DM_GWPipeline_UnknownError",
      "parameters": {},
      "details": [
        {
          "code": "DM_ErrorDetailNameCode_UnderlyingErrorMessage",
          "detail": {
            "type": 1,
            "value": "The parameter is incorrect.\r\n"
          }
        },
        {
          "code": "DM_ErrorDetailNameCode_UnderlyingHResult",
          "detail": {
            "type": 1,
            "value": "-2146893785"
          }
        }
      ],
      "exceptionCulprit": 1
    }
  }
}

1 个答案:

答案 0 :(得分:0)

您可以通过升级到支持2048位的最新RSA加密来解决此问题。