Azure SharedKeyCredentials失败,输入字节数组的4字节结尾单元错误

时间:2018-09-17 21:55:51

标签: azure-storage azure-java-sdk

尝试从Storage-blobs-java-v10-quickstart运行简单示例并将API reference document中列出的引用用作:

String accountName = "acsazurestore";
String accountKey = "qjC6s44AmSbAkJ7Xqdsks/jjZDIYRTY8qg...."; [not the full one]

SharedKeyCredentials sharedKeyCredentials = new SharedKeyCredentials(accountName, accountKey);

编译(mvn compile exec:java)时,程序失败,并显示以下错误消息:

Caused by: java.lang.IllegalArgumentException: Input byte array has wrong 4-byte ending unit
at java.util.Base64$Decoder.decode0(Base64.java:704)
at java.util.Base64$Decoder.decode(Base64.java:526)
at java.util.Base64$Decoder.decode(Base64.java:549)
at com.microsoft.azure.storage.blob.SharedKeyCredentials.<init>(SharedKeyCredentials.java:60)
at quickstart.Quickstart.main(Quickstart.java:162)

感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

即使使用伪造的帐户密钥也应该可以使用。我假设它可能发生在其他代码行中。 如果不是这种情况。我建议您可以创建一个新项目并添加以下依赖项。

<dependency>
        <groupId>com.microsoft.azure</groupId>

        <artifactId>azure-storage-blob</artifactId>

        <version>10.1.0</version>

</dependency>

然后添加以下代码并再次进行测试。

public static void main(String... args) throws Exception
    {
        String accountName = "accountName";
        String accountKey = "xxxxxxxxxxx";

        try {
            SharedKeyCredentials sharedKeyCredentials = new SharedKeyCredentials(accountName, accountKey);
            System.out.print(sharedKeyCredentials.getAccountName());
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        }

    }

测试结果:

enter image description here