在使用AWS加密SDK设置Maven项目时遇到困难。

huangapple 未分类评论48阅读模式
英文:

Difficulties setting up maven project using AWS encryption SDK

问题

以下是您的翻译内容:

我在IntelliJ中的Maven项目中有以下的pom文件 -

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>aws-encryption</groupId>
    <artifactId>aws-encryption</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencyManagement>
     <dependencies>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-encryption-sdk-java</artifactId>
            <version>1.6.1</version>
        </dependency>
         <dependency>
             <groupId>com.amazonaws</groupId>
             <artifactId>aws-java-sdk</artifactId>
             <version>1.11.327</version>
         </dependency>

         <!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-ext-jdk15on -->
         <dependency>
             <groupId>org.bouncycastle</groupId>
             <artifactId>bcprov-ext-jdk15on</artifactId>
             <version>1.65</version>
         </dependency>

         <dependency>
             <groupId>com.amazonaws</groupId>
             <artifactId>aws-java-sdk-kms</artifactId>
             <version>1.11.765</version>
         </dependency>

     </dependencies>
    </dependencyManagement>
</project>

还有以下的类文件 -

package com.aws.encrypt;

import java.util.Collections;
import java.util.Map;

public class Main {

    private static String keyArn;
    private static String data;

    public static void main(String[] args) {
        keyArn = args[0];
        data = args[1];

        // Instantiate the SDK
        final AwsCrypto crypto = new AwsCrypto();

        // Set up the KmsMasterKeyProvider backed by the default credentials
        final KmsMasterKeyProvider prov = KmsMasterKeyProvider.builder().withKeysForEncryption(keyArn).build();

        // Encrypt the data
        //
        // Most encrypted data should have an associated encryption context
        // to protect integrity. This sample uses placeholder values.
        //
        // For more information see:
        // blogs.aws.amazon.com/security/post/Tx2LZ6WBJJANTNW/How-to-Protect-the-Integrity-of-Your-Encrypted-Data-by-Using-AWS-Key-Management
        final Map<String, String> context = Collections.singletonMap("Example", "String");

        final String ciphertext = crypto.encryptString(prov, data, context).getResult();
        System.out.println("Ciphertext: " + ciphertext);

        // Decrypt the data
        final CryptoResult<String, KmsMasterKey> decryptResult = crypto.decryptString(prov, ciphertext);

        // Before returning the plaintext, verify that the customer master key that
        // was used in the encryption operation was the one supplied to the master key provider.
        if (!decryptResult.getMasterKeyIds().get(0).equals(keyArn)) {
            throw new IllegalStateException("Wrong key ID!");
        }

        // Also, verify that the encryption context in the result contains the
        // encryption context supplied to the encryptString method. Because the
        // SDK can add values to the encryption context, don't require that
        // the entire context matches.
        for (final Map.Entry<String, String> e : context.entrySet()) {
            if (!e.getValue().equals(decryptResult.getEncryptionContext().get(e.getKey()))) {
                throw new IllegalStateException("Wrong Encryption Context!");
            }
        }

        // Now we can return the plaintext data
        System.out.println("Decrypted: " + decryptResult.getResult());
    }

}

似乎所有的依赖jar包都没有被下载。
我只在我的本地仓库中找到了aws-encryption-1.0-SNAPSHOT.jar。
不确定为什么其他的没有被下载。我也尝试了mvn clean install。

我在我的存储库设置中没有发现任何问题 -

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                        http://maven.apache.org/xsd/settings-1.0.0.xsd">

<localRepository>/Users/sandeepan.nath/.m2/repository</localRepository>

</settings>

可能出了什么问题。

英文:

I have the following pom file in my maven project on IntelliJ-

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

    &lt;groupId&gt;aws-encryption&lt;/groupId&gt;
    &lt;artifactId&gt;aws-encryption&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;dependencyManagement&gt;
     &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
            &lt;artifactId&gt;aws-encryption-sdk-java&lt;/artifactId&gt;
            &lt;version&gt;1.6.1&lt;/version&gt;
        &lt;/dependency&gt;
         &lt;dependency&gt;
             &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
             &lt;artifactId&gt;aws-java-sdk&lt;/artifactId&gt;
             &lt;version&gt;1.11.327&lt;/version&gt;
         &lt;/dependency&gt;

         &lt;!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-ext-jdk15on --&gt;
         &lt;dependency&gt;
             &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
             &lt;artifactId&gt;bcprov-ext-jdk15on&lt;/artifactId&gt;
             &lt;version&gt;1.65&lt;/version&gt;
         &lt;/dependency&gt;

         &lt;dependency&gt;
             &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
             &lt;artifactId&gt;aws-java-sdk-kms&lt;/artifactId&gt;
             &lt;version&gt;1.11.765&lt;/version&gt;
         &lt;/dependency&gt;

     &lt;/dependencies&gt;
    &lt;/dependencyManagement&gt;
&lt;/project&gt;

And the following class file -

package com.aws.encrypt;

import java.util.Collections;
import java.util.Map;

public class Main {

    private static String keyArn;
    private static String data;

    public static void main(String[] args) {
        keyArn = args[0];
        data = args[1];

        // Instantiate the SDK
        final AwsCrypto crypto = new AwsCrypto();

        // Set up the KmsMasterKeyProvider backed by the default credentials
        final KmsMasterKeyProvider prov = KmsMasterKeyProvider.builder().withKeysForEncryption(keyArn).build();

        // Encrypt the data
        //
        // Most encrypted data should have an associated encryption context
        // to protect integrity. This sample uses placeholder values.
        //
        // For more information see:
        // blogs.aws.amazon.com/security/post/Tx2LZ6WBJJANTNW/How-to-Protect-the-Integrity-of-Your-Encrypted-Data-by-Using-AWS-Key-Management
        final Map&lt;String, String&gt; context = Collections.singletonMap(&quot;Example&quot;, &quot;String&quot;);

        final String ciphertext = crypto.encryptString(prov, data, context).getResult();
        System.out.println(&quot;Ciphertext: &quot; + ciphertext);

        // Decrypt the data
        final CryptoResult&lt;String, KmsMasterKey&gt; decryptResult = crypto.decryptString(prov, ciphertext);

        // Before returning the plaintext, verify that the customer master key that
        // was used in the encryption operation was the one supplied to the master key provider.
        if (!decryptResult.getMasterKeyIds().get(0).equals(keyArn)) {
            throw new IllegalStateException(&quot;Wrong key ID!&quot;);
        }

        // Also, verify that the encryption context in the result contains the
        // encryption context supplied to the encryptString method. Because the
        // SDK can add values to the encryption context, don&#39;t require that
        // the entire context matches.
        for (final Map.Entry&lt;String, String&gt; e : context.entrySet()) {
            if (!e.getValue().equals(decryptResult.getEncryptionContext().get(e.getKey()))) {
                throw new IllegalStateException(&quot;Wrong Encryption Context!&quot;);
            }
        }

        // Now we can return the plaintext data
        System.out.println(&quot;Decrypted: &quot; + decryptResult.getResult());
    }

}

It seems all the dependency jars were not downloaded.
I can only find aws-encryption-1.0-SNAPSHOT.jar in my local repository.
Not sure why the others did not get downloaded. I tried mvn clean install as well.

I don't see any issues with my repository settings -

&lt;settings xmlns=&quot;http://maven.apache.org/SETTINGS/1.0.0&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xsi:schemaLocation=&quot;http://maven.apache.org/SETTINGS/1.0.0
                        http://maven.apache.org/xsd/settings-1.0.0.xsd">

&lt;localRepository&gt;/Users/sandeepan.nath/.m2/repository&lt;/localRepository&gt;

&lt;/settings&gt;

What could be wrong.

答案1

得分: 0

你尝试过使用Maven的调试标志了吗?
例如:

mvn clean install -X

这可能会让你对底层实际发生的情况有一些线索。
希望对你有所帮助。
更新:
依赖管理是为了在父级pom中将依赖项分组,供子项目使用。如果情况不是这样的,只需单独使用dependencies(依赖项)即可。

英文:

Have you tried the maven debug flag?
eg

mvn clean install -X

it may give you some clue about what actually happens under the hood
hth
update:
dependency management is for grouping dependencies for child projects, in a parent pom. If this is not the case one can just use dependencies alone.

huangapple
  • 本文由 发表于 2020年5月29日 23:14:58
  • 转载请务必保留本文链接:https://java.coder-hub.com/62089200.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定