Skip to content

Instantly share code, notes, and snippets.

+---------------------------------------+-----------+
| Encryption | Max bytes |
+---------------------------------------+-----------+
| RSA/ECB/NoPadding | 256 |
| RSA/ECB/PKCS1Padding | 245 |
| RSA/ECB/OAEPPadding | 214 |
| RSA/ECB/OAEPWithSHA-1AndMGF1Padding | 214 |
| RSA/ECB/OAEPWithSHA-224AndMGF1Padding | 198 |
| RSA/ECB/OAEPWithSHA-256AndMGF1Padding | 190 |
| RSA/ECB/OAEPWithSHA-384AndMGF1Padding | 158 |
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA");
kpGen.initialize(2048);
KeyPair keyPair = kpGen.generateKeyPair();
Random random = new SecureRandom();
byte[] data = new byte[256];
random.nextBytes(data);
Cipher cipher = Cipher.getInstance(__RSA_ENCRYPTION__);
cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic());
Name Supported key type(s) Cost Programming Interface
AWS HSM AES, RSA, EC at least $1044 per month C/C++/Java
AWS KMS AES/GCM $1/key/month + $0.03 per 10k request AWS SDK
Azure Key Vault RSA, EC $1/key/month + $0.03 per 10k request Azure SDK
@samngms
samngms / MyKeyVaultTest.java
Last active September 12, 2018 04:45
Code sample for Azure KeyVault
import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.credentials.ApplicationTokenCredentials;
import com.microsoft.azure.keyvault.KeyVaultClient;
import com.microsoft.azure.keyvault.models.KeyOperationResult;
import com.microsoft.azure.keyvault.webkey.JsonWebKeyEncryptionAlgorithm;
public class MyKeyVaultTest {
public static String CLIENT_ID = "<<your application id>>";
public static String DOMAIN_ID = "<<your orgnization id>>";
public static String SECRET = "<<your secret>>";