-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: vamsi-amazon <reddyvam@amazon.com>
- Loading branch information
1 parent
11d0d6d
commit eb77575
Showing
23 changed files
with
702 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
core/src/main/java/org/opensearch/sql/encryptor/CredentialInfoEncryptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* | ||
* * Copyright OpenSearch Contributors | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.opensearch.sql.encryptor; | ||
|
||
public interface CredentialInfoEncryptor { | ||
|
||
String encrypt(String plainText); | ||
|
||
String decrypt(String encryptedText); | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
core/src/main/java/org/opensearch/sql/encryptor/CredentialInfoEncryptorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.opensearch.sql.encryptor;/* | ||
* | ||
* * Copyright OpenSearch Contributors | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
|
||
import com.amazonaws.encryptionsdk.AwsCrypto; | ||
import com.amazonaws.encryptionsdk.CommitmentPolicy; | ||
import com.amazonaws.encryptionsdk.CryptoResult; | ||
import com.amazonaws.encryptionsdk.jce.JceMasterKey; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
import javax.crypto.spec.SecretKeySpec; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class CredentialInfoEncryptorImpl implements CredentialInfoEncryptor { | ||
|
||
private final String masterKey; | ||
|
||
@Override | ||
public String encrypt(String plainText) { | ||
|
||
final AwsCrypto crypto = AwsCrypto.builder() | ||
.withCommitmentPolicy(CommitmentPolicy.RequireEncryptRequireDecrypt) | ||
.build(); | ||
|
||
JceMasterKey jceMasterKey | ||
= JceMasterKey.getInstance(new SecretKeySpec(masterKey.getBytes(), "AES"), "Custom", "", | ||
"AES/GCM/NoPadding"); | ||
|
||
final CryptoResult<byte[], JceMasterKey> encryptResult = crypto.encryptData(jceMasterKey, | ||
plainText.getBytes(StandardCharsets.UTF_8)); | ||
return Base64.getEncoder().encodeToString(encryptResult.getResult()); | ||
} | ||
|
||
@Override | ||
public String decrypt(String encryptedText) { | ||
final AwsCrypto crypto = AwsCrypto.builder() | ||
.withCommitmentPolicy(CommitmentPolicy.RequireEncryptRequireDecrypt) | ||
.build(); | ||
|
||
JceMasterKey jceMasterKey | ||
= JceMasterKey.getInstance(new SecretKeySpec(masterKey.getBytes(), "AES"), "Custom", "", | ||
"AES/GCM/NoPadding"); | ||
|
||
final CryptoResult<byte[], JceMasterKey> decryptedResult | ||
= crypto.decryptData(jceMasterKey, Base64.getDecoder().decode(encryptedText)); | ||
return new String(decryptedResult.getResult()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.