英文:
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-
<?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>
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<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());
    }
}
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 -
<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>
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.
专注分享java语言的经验与见解,让所有开发者获益!



评论