Skip to content

Commit f71623d

Browse files
Initial Commit
1 parent ab92f50 commit f71623d

File tree

80 files changed

+13581
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+13581
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
eclipse-bin/
2+
target/
3+
.settings/
4+
.project
5+
.classpath

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: java
2+
jdk:
3+
- openjdk8
4+
- oraclejdk8
5+
install: /bin/true
6+
script: mvn install --quiet -Dgpg.skip=true -DskipTests=true

NOTICE.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
AWS KMS Encryption Client SDK
2+
Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
THIRD PARTY COMPONENTS
5+
**********************
6+
This software includes third party software subject to the following copyrights:
7+
8+
-Cryptographic functions from Bouncy Castle Crypto APIs for Java - Copyright
9+
2000-2013 The Legion of the Bouncy Castle
10+
11+
The licenses for these third party components are included in LICENSE.txt

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# AWS Encryption SDK for Java
2+
3+
The AWS Encryption SDK enables secure client-side encryption by using cryptography best practices to protect your data and the encryption keys used to protect that data. Each data object is protected with a unique data encryption key (DEK), and the DEK is protected with a key encryption key (KEK) called a *master key*. The encrypted DEK is combined with the encrypted data into a single encrypted message, so you don't need to keep track of the DEKs for your data. The SDK supports master keys in the [AWS Key Management Service](https://aws.amazon.com/kms/) (AWS KMS), and it also provides APIs to define and use other master key providers. The SDK provides methods for encrypting and decrypting strings, byte arrays, and byte streams. For details, see the [example code][examples].
4+
5+
For more details about the design and architecture of the SDK, see the [official documentation](https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/).
6+
7+
## Getting Started
8+
9+
### Required Prerequisites
10+
To use this SDK you must have:
11+
12+
* **A Java development environment**
13+
If you do not have one, go to [Java SE Downloads](https://www.oracle.com/technetwork/java/javase/downloads/index.html) and then download and install the Java SE Development Kit (JDK).
14+
15+
* **Bouncy Castle**
16+
Bouncy Castle provides a cryptography API for Java. If you do not have Bouncy Castle, go to https://bouncycastle.org/latest_releases.html and then download the provider file that corresponds to your JDK.
17+
18+
### Optional Prerequisites
19+
20+
You don't need an Amazon Web Services (AWS) account to use this SDK, but some of the [example code][examples] requires an AWS account, a customer master key (CMK) in AWS KMS, and the AWS SDK for Java.
21+
22+
* **To sign up for AWS**, go to [Sign In or Create an AWS Account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) and choose **I am a new user.** Follow the instructions to sign up and create an AWS account.
23+
24+
* **To create a CMK in AWS KMS**, go to [Creating Keys](https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html) in the KMS documentation and then follow the instructions on that page.
25+
26+
* **To download and install the AWS SDK for Java**, go to [Installing the AWS SDK for Java](https://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-install-sdk.html) in the *AWS SDK for Java Developer Guide* and then follow the instructions on that page.
27+
28+
### Download the SDK
29+
30+
### Get Started
31+
32+
The following code sample demonstrates how to get started:
33+
34+
1. Instantiate the SDK
35+
2. Define the master key provider
36+
3. Encrypt and decrypt data
37+
38+
```java
39+
// This sample code encrypts and then decrypts a string using a KMS master key.
40+
// You provide the KMS key ARN and plaintext string as arguments.
41+
package com.amazonaws.crypto.examples;
42+
43+
import java.util.Collections;
44+
import java.util.Map;
45+
46+
import com.amazonaws.encryptionsdk.AwsCrypto;
47+
import com.amazonaws.encryptionsdk.CryptoResult;
48+
import com.amazonaws.encryptionsdk.kms.KmsMasterKey;
49+
import com.amazonaws.encryptionsdk.kms.KmsMasterKeyProvider;
50+
51+
public class StringExample {
52+
private static String keyArn;
53+
private static String data;
54+
55+
public static void main(final String[] args) {
56+
keyArn = args[0];
57+
data = args[1];
58+
59+
// Instantiate the SDK
60+
final AwsCrypto crypto = new AwsCrypto();
61+
62+
// Set up the master key provider
63+
final KmsMasterKeyProvider prov = new KmsMasterKeyProvider(keyArn);
64+
65+
// Encrypt the data
66+
//
67+
// NOTE: Encrypted data should have associated encryption context
68+
// to protect integrity. For this example, just use a placeholder
69+
// value. For more information about encryption context, see
70+
// https://amzn.to/1nSbe9X (blogs.aws.amazon.com)
71+
final Map<String, String> context = Collections.singletonMap("Example", "String");
72+
73+
final String ciphertext = crypto.encryptString(prov, data, context).getResult();
74+
System.out.println("Ciphertext: " + ciphertext);
75+
76+
// Decrypt the data
77+
final CryptoResult<String, KmsMasterKey> decryptResult = crypto.decryptString(prov, ciphertext);
78+
// Check the encryption context (and ideally the master key) to
79+
// ensure this is the expected ciphertext
80+
if (!decryptResult.getMasterKeyIds().get(0).equals(keyArn)) {
81+
throw new IllegalStateException("Wrong key id!");
82+
}
83+
84+
// The SDK may add information to the encryption context, so check to
85+
// ensure all of the values are present
86+
for (final Map.Entry<String, String> e : context.entrySet()) {
87+
if (!e.getValue().equals(decryptResult.getEncryptionContext().get(e.getKey()))) {
88+
throw new IllegalStateException("Wrong Encryption Context!");
89+
}
90+
}
91+
92+
// The data is correct, so output it.
93+
System.out.println("Decrypted: " + decryptResult.getResult());
94+
}
95+
}
96+
```
97+
98+
For more examples, look in the [examples directory][examples].
99+
100+
## FAQ
101+
102+
See the [Frequently Asked Questions](https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/faq.html) page in the official documentation.
103+
104+
[examples]: examples/com/amazonaws/crypto/examples/

pom.xml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
4+
<groupId>com.amazonaws</groupId>
5+
<artifactId>aws-encryption-sdk-java</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
9+
<name>aws-encryption-sdk-java</name>
10+
<description>AWS Encryption SDK for Java</description>
11+
<url>https://github.com/awslabs/aws-encryption-sdk-java</url>
12+
13+
<licenses>
14+
<license>
15+
<name>Apache License, Version 2.0</name>
16+
<url>https://aws.amazon.com/apache2.0</url>
17+
<distribution>repo</distribution>
18+
</license>
19+
</licenses>
20+
21+
<developers>
22+
<developer>
23+
<id>amazonwebservices</id>
24+
<organization>Amazon Web Services</organization>
25+
<organizationUrl>https://aws.amazon.com</organizationUrl>
26+
<roles>
27+
<role>developer</role>
28+
</roles>
29+
</developer>
30+
</developers>
31+
32+
<properties>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
</properties>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>com.amazonaws</groupId>
39+
<artifactId>aws-java-sdk</artifactId>
40+
<version>1.10.61</version>
41+
<optional>true</optional>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>org.bouncycastle</groupId>
46+
<artifactId>bcprov-ext-jdk15on</artifactId>
47+
<version>1.54</version>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>junit</groupId>
52+
<artifactId>junit</artifactId>
53+
<version>4.8.1</version>
54+
<scope>test</scope>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>org.apache.commons</groupId>
59+
<artifactId>commons-lang3</artifactId>
60+
<version>3.4</version>
61+
</dependency>
62+
</dependencies>
63+
64+
<!--Custom repository:-->
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.apache.maven.plugins</groupId>
69+
<artifactId>maven-compiler-plugin</artifactId>
70+
<version>3.1</version>
71+
<configuration>
72+
<source>1.7</source>
73+
<target>1.7</target>
74+
</configuration>
75+
</plugin>
76+
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-javadoc-plugin</artifactId>
80+
<version>2.9.1</version>
81+
<configuration>
82+
<excludePackageNames>*.internal:*.transform</excludePackageNames>
83+
<minmemory>128m</minmemory>
84+
<maxmemory>1024m</maxmemory>
85+
</configuration>
86+
</plugin>
87+
</plugins>
88+
</build>
89+
90+
<profiles>
91+
<profile>
92+
<id>publishing</id>
93+
94+
<distributionManagement>
95+
<snapshotRepository>
96+
<id>ossrh</id>
97+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
98+
</snapshotRepository>
99+
</distributionManagement>
100+
101+
<build>
102+
<plugins>
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-gpg-plugin</artifactId>
106+
<executions>
107+
<execution>
108+
<id>sign-artifacts</id>
109+
<phase>verify</phase>
110+
<goals>
111+
<goal>sign</goal>
112+
</goals>
113+
</execution>
114+
</executions>
115+
</plugin>
116+
117+
<plugin>
118+
<groupId>org.sonatype.plugins</groupId>
119+
<artifactId>nexus-staging-maven-plugin</artifactId>
120+
<version>1.6.3</version>
121+
<extensions>true</extensions>
122+
<configuration>
123+
<serverId>ossrh</serverId>
124+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
125+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
126+
</configuration>
127+
</plugin>
128+
129+
</plugins>
130+
</build>
131+
</profile>
132+
</profiles>
133+
</project>

0 commit comments

Comments
 (0)