Permalink
Browse files

Fix for issue 7

  • Loading branch information...
1 parent bab4341 commit 15f305e522bd3c85eec7cc46a50e18385f324b9e @bosakm bosakm committed Aug 21, 2012
Showing with 4,145 additions and 1,967 deletions.
  1. +84 −70 ...main/java/com/google/code/springcryptoutils/core/cipher/asymmetric/Base64EncodedCiphererImpl.java
  2. +99 −85 ...le/code/springcryptoutils/core/cipher/asymmetric/Base64EncodedCiphererWithChooserByKeyIdImpl.java
  3. +72 −58 src/main/java/com/google/code/springcryptoutils/core/cipher/asymmetric/CiphererImpl.java
  4. +79 −65 ...java/com/google/code/springcryptoutils/core/cipher/asymmetric/CiphererWithChooserByKeyIdImpl.java
  5. +107 −91 src/main/java/com/google/code/springcryptoutils/core/cipher/symmetric/Base64EncodedCiphererImpl.java
  6. +132 −118 ...m/google/code/springcryptoutils/core/cipher/symmetric/Base64EncodedCiphererWithStaticKeyImpl.java
  7. +64 −42 ...n/java/com/google/code/springcryptoutils/core/cipher/symmetric/Base64EncodedKeyGeneratorImpl.java
  8. +76 −63 src/main/java/com/google/code/springcryptoutils/core/cipher/symmetric/CiphererImpl.java
  9. +107 −91 src/main/java/com/google/code/springcryptoutils/core/cipher/symmetric/CiphererWithStaticKeyImpl.java
  10. +45 −29 src/main/java/com/google/code/springcryptoutils/core/cipher/symmetric/KeyGeneratorImpl.java
  11. +104 −90 src/main/java/com/google/code/springcryptoutils/core/digest/DigesterImpl.java
  12. +46 −22 src/main/java/com/google/code/springcryptoutils/core/keystore/Base64EncodedKeyStoreFactoryBean.java
  13. +1 −1 src/main/java/com/google/code/springcryptoutils/core/keystore/InitializationException.java
  14. +63 −46 src/main/java/com/google/code/springcryptoutils/core/keystore/KeyStoreFactoryBean.java
  15. +38 −27 src/main/java/com/google/code/springcryptoutils/core/mac/Base64EncodedMacImpl.java
  16. +52 −38 src/main/java/com/google/code/springcryptoutils/core/mac/MacImpl.java
  17. +61 −50 src/main/java/com/google/code/springcryptoutils/core/signature/Base64EncodedSignerImpl.java
  18. +84 −71 ...oogle/code/springcryptoutils/core/signature/Base64EncodedSignerWithChooserByPrivateKeyIdImpl.java
  19. +91 −79 .../com/google/code/springcryptoutils/core/signature/Base64EncodedSignerWithChoosersByAliasImpl.java
  20. +57 −46 src/main/java/com/google/code/springcryptoutils/core/signature/Base64EncodedVerifierImpl.java
  21. +85 −72 ...ogle/code/springcryptoutils/core/signature/Base64EncodedVerifierWithChooserByPublicKeyIdImpl.java
  22. +94 −80 ...om/google/code/springcryptoutils/core/signature/Base64EncodedVerifierWithChoosersByAliasImpl.java
  23. +53 −40 src/main/java/com/google/code/springcryptoutils/core/signature/SignerImpl.java
  24. +61 −49 ...in/java/com/google/code/springcryptoutils/core/signature/SignerWithChooserByPrivateKeyIdImpl.java
  25. +77 −66 src/main/java/com/google/code/springcryptoutils/core/signature/SignerWithChoosersByAliasImpl.java
  26. +58 −44 src/main/java/com/google/code/springcryptoutils/core/signature/VerifierImpl.java
  27. +63 −50 ...n/java/com/google/code/springcryptoutils/core/signature/VerifierWithChooserByPublicKeyIdImpl.java
  28. +80 −67 src/main/java/com/google/code/springcryptoutils/core/signature/VerifierWithChoosersByAliasImpl.java
  29. +13 −10 .../code/springcryptoutils/core/spring/cipher/asymmetric/AsymmetricCiphererBeanDefinitionParser.java
  30. +13 −10 ...utils/core/spring/cipher/asymmetric/AsymmetricCiphererWithChooserByKeyIdBeanDefinitionParser.java
  31. +14 −11 ...ryptoutils/core/spring/cipher/asymmetric/Base64EncodedAsymmetricCiphererBeanDefinitionParser.java
  32. +16 −12 ...ring/cipher/asymmetric/Base64EncodedAsymmetricCiphererWithChooserByKeyIdBeanDefinitionParser.java
  33. +15 −12 ...gcryptoutils/core/spring/cipher/symmetric/Base64EncodedSymmetricCiphererBeanDefinitionParser.java
  34. +17 −14 ...core/spring/cipher/symmetric/Base64EncodedSymmetricCiphererWithStaticKeyBeanDefinitionParser.java
  35. +12 −9 ...ptoutils/core/spring/cipher/symmetric/Base64EncodedSymmetricKeyGeneratorBeanDefinitionParser.java
  36. +13 −10 ...le/code/springcryptoutils/core/spring/cipher/symmetric/SymmetricCiphererBeanDefinitionParser.java
  37. +15 −12 ...gcryptoutils/core/spring/cipher/symmetric/SymmetricCiphererWithStaticKeyBeanDefinitionParser.java
  38. +11 −8 ...ode/springcryptoutils/core/spring/cipher/symmetric/SymmetricKeyGeneratorBeanDefinitionParser.java
  39. +13 −10 src/main/java/com/google/code/springcryptoutils/core/spring/digest/DigesterBeanDefinitionParser.java
  40. +13 −10 ...google/code/springcryptoutils/core/spring/keystore/Base64EncodedKeyStoreBeanDefinitionParser.java
  41. +13 −10 ...ain/java/com/google/code/springcryptoutils/core/spring/keystore/KeyStoreBeanDefinitionParser.java
  42. +12 −9 .../java/com/google/code/springcryptoutils/core/spring/mac/Base64EncodedMacBeanDefinitionParser.java
  43. +12 −9 src/main/java/com/google/code/springcryptoutils/core/spring/mac/MacBeanDefinitionParser.java
  44. +13 −10 ...utils/core/spring/signature/Base64EncodedSignerWithChooserByPrivateKeyIdBeanDefinitionParser.java
  45. +13 −10 ...cryptoutils/core/spring/signature/Base64EncodedSignerWithChoosersByAliasBeanDefinitionParser.java
  46. +13 −10 ...oogle/code/springcryptoutils/core/spring/signature/Base64EncodedVerifierBeanDefinitionParser.java
  47. +13 −10 ...tils/core/spring/signature/Base64EncodedVerifierWithChooserByPublicKeyIdBeanDefinitionParser.java
  48. +13 −10 ...yptoutils/core/spring/signature/Base64EncodedVerifierWithChoosersByAliasBeanDefinitionParser.java
  49. +12 −9 ...main/java/com/google/code/springcryptoutils/core/spring/signature/SignerBeanDefinitionParser.java
  50. +12 −9 .../springcryptoutils/core/spring/signature/SignerWithChooserByPrivateKeyIdBeanDefinitionParser.java
  51. +12 −9 ...e/code/springcryptoutils/core/spring/signature/SignerWithChoosersByAliasBeanDefinitionParser.java
  52. +12 −9 ...in/java/com/google/code/springcryptoutils/core/spring/signature/VerifierBeanDefinitionParser.java
  53. +12 −9 ...springcryptoutils/core/spring/signature/VerifierWithChooserByPublicKeyIdBeanDefinitionParser.java
  54. +12 −9 ...code/springcryptoutils/core/spring/signature/VerifierWithChoosersByAliasBeanDefinitionParser.java
  55. +27 −0 src/main/resources/com/google/code/springcryptoutils/core/spring/crypt.xsd
  56. +60 −0 .../code/springcryptoutils/core/cipher/asymmetric/Base64EncodedCiphererImplSpecificProviderTest.java
  57. +46 −45 .../java/com/google/code/springcryptoutils/core/cipher/asymmetric/Base64EncodedCiphererImplTest.java
  58. +60 −0 ...utils/core/cipher/asymmetric/Base64EncodedCiphererWithChooserByKeyIdSpecificProviderImplTest.java
  59. +60 −0 ...va/com/google/code/springcryptoutils/core/cipher/asymmetric/CiphererImplSpecificProviderTest.java
  60. +60 −0 .../springcryptoutils/core/cipher/asymmetric/CiphererWithChooserByKeyIdImplSpecificProviderTest.java
  61. +79 −0 ...e/code/springcryptoutils/core/cipher/symmetric/Base64EncodedCiphererImplSpecificProviderTest.java
  62. +68 −0 ...cryptoutils/core/cipher/symmetric/Base64EncodedCiphererWithStaticKeyImplSpecificProviderTest.java
  63. +39 −0 ...de/springcryptoutils/core/cipher/symmetric/Base64EncodedKeyGeneratorImplSpecificProviderTest.java
  64. +71 −0 ...ava/com/google/code/springcryptoutils/core/cipher/symmetric/CiphererImplSpecificProviderTest.java
  65. +60 −0 ...e/code/springcryptoutils/core/cipher/symmetric/CiphererWithStaticKeyImplSpecificProviderTest.java
  66. +41 −0 ...com/google/code/springcryptoutils/core/cipher/symmetric/KeyGeneratorImplSpecificProviderTest.java
  67. +26 −0 ...google/code/springcryptoutils/core/digest/DigesterImplInBase64OutputModeSpecificProviderTest.java
  68. +28 −0 ...le/code/springcryptoutils/core/keystore/Base64EncodedKeyStoreFactoryBeanSpecificProviderTest.java
  69. +28 −0 .../java/com/google/code/springcryptoutils/core/keystore/KeyStoreFactoryBeanSpecifyProviderTest.java
  70. +12 −12 src/test/java/com/google/code/springcryptoutils/core/keystore/KeyStoreFactoryBeanTest.java
  71. +32 −0 ...est/java/com/google/code/springcryptoutils/core/mac/Base64EncodedMacImplSpecificProviderTest.java
  72. +31 −0 src/test/java/com/google/code/springcryptoutils/core/mac/MacImplSpecificProviderTest.java
  73. +63 −0 ...code/springcryptoutils/core/signature/Base64EncodedSignerAndVerifierImplSpecificProviderTest.java
  74. +136 −0 ...ils/core/signature/Base64EncodedSignerAndVerifierWithChoosersByAliasImplSpecificProviderTest.java
  75. +75 −0 ...ils/core/signature/Base64EncodedSignerAndVerifierWithChoosersByKeyIdImplSpecificProviderTest.java
  76. +63 −0 ...a/com/google/code/springcryptoutils/core/signature/SignerAndVerifierImplSpecificProviderTest.java
  77. +137 −0 ...pringcryptoutils/core/signature/SignerAndVerifierWithChoosersByAliasImplSpecificProviderTest.java
  78. +75 −0 ...pringcryptoutils/core/signature/SignerAndVerifierWithChoosersByKeyIdImplSpecificProviderTest.java
  79. +17 −0 ...pringcryptoutils/core/cipher/asymmetric/Base64EncodedCiphererImplSpecificProviderTest-context.xml
  80. +23 −0 ...ore/cipher/asymmetric/Base64EncodedCiphererWithChooserByKeyIdSpecificProviderImplTest-context.xml
  81. +17 −0 ...google/code/springcryptoutils/core/cipher/asymmetric/CiphererImplSpecificProviderTest-context.xml
  82. +23 −0 ...cryptoutils/core/cipher/asymmetric/CiphererWithChooserByKeyIdImplSpecificProviderTest-context.xml
  83. +17 −0 ...springcryptoutils/core/cipher/symmetric/Base64EncodedCiphererImplSpecificProviderTest-context.xml
  84. +21 −0 ...tils/core/cipher/symmetric/Base64EncodedCiphererWithStaticKeyImplSpecificProviderTest-context.xml
  85. +9 −0 ...ngcryptoutils/core/cipher/symmetric/Base64EncodedKeyGeneratorImplSpecificProviderTest-context.xml
  86. +15 −0 .../google/code/springcryptoutils/core/cipher/symmetric/CiphererImplSpecificProviderTest-context.xml
  87. +21 −0 ...springcryptoutils/core/cipher/symmetric/CiphererWithStaticKeyImplSpecificProviderTest-context.xml
  88. +9 −0 ...gle/code/springcryptoutils/core/cipher/symmetric/KeyGeneratorImplSpecificProviderTest-context.xml
  89. +9 −0 ...code/springcryptoutils/core/digest/DigesterImplInBase64OutputModeSpecificProviderTest-context.xml
  90. +40 −0 .../springcryptoutils/core/keystore/Base64EncodedKeyStoreFactoryBeanSpecificProviderTest-context.xml
  91. +9 −0 ...om/google/code/springcryptoutils/core/keystore/KeyStoreFactoryBeanSpecifyProviderTest-context.xml
  92. +13 −0 ...s/com/google/code/springcryptoutils/core/mac/Base64EncodedMacImplSpecificProviderTest-context.xml
  93. +13 −0 ...test/resources/com/google/code/springcryptoutils/core/mac/MacImplSpecificProviderTest-context.xml
  94. +17 −0 ...ringcryptoutils/core/signature/Base64EncodedSignerAndVerifierImplSpecificProviderTest-context.xml
  95. +27 −0 ...e/signature/Base64EncodedSignerAndVerifierWithChoosersByAliasImplSpecificProviderTest-context.xml
  96. +28 −0 ...e/signature/Base64EncodedSignerAndVerifierWithChoosersByKeyIdImplSpecificProviderTest-context.xml
  97. +17 −0 ...oogle/code/springcryptoutils/core/signature/SignerAndVerifierImplSpecificProviderTest-context.xml
  98. +25 −0 ...yptoutils/core/signature/SignerAndVerifierWithChoosersByAliasImplSpecificProviderTest-context.xml
  99. +26 −0 ...yptoutils/core/signature/SignerAndVerifierWithChoosersByKeyIdImplSpecificProviderTest-context.xml
@@ -1,89 +1,103 @@
package com.google.code.springcryptoutils.core.cipher.asymmetric;
-import com.google.code.springcryptoutils.core.cipher.Mode;
-import org.apache.commons.codec.binary.Base64;
+import java.security.Key;
import javax.crypto.Cipher;
-import java.security.Key;
+
+import org.apache.commons.codec.binary.Base64;
+
+import com.google.code.springcryptoutils.core.cipher.Mode;
/**
* The default implementation for performing asymmetric encryption/decryption
* with base64 encoded strings and a static key.
- *
+ *
* @author Mirko Caserta (mirko.caserta@gmail.com)
*/
public class Base64EncodedCiphererImpl implements Base64EncodedCipherer {
- private String algorithm = "RSA";
- private String charsetName = "UTF-8";
- private Mode mode;
- private Key key;
+ private String algorithm = "RSA";
+ private String charsetName = "UTF-8";
+ private String provider;
+ private Mode mode;
+ private Key key;
+
+ /**
+ * The asymmetric key algorithm. The default is RSA.
+ *
+ * @param algorithm the asymmetric key algorithm
+ */
+ public void setAlgorithm(String algorithm) {
+ this.algorithm = algorithm;
+ }
- /**
- * The asymmetric key algorithm. The default is RSA.
- *
- * @param algorithm the asymmetric key algorithm
- */
- public void setAlgorithm(String algorithm) {
- this.algorithm = algorithm;
- }
+ /**
+ * The charset used when a message must be converted into a raw byte array.
+ * Default is UTF-8.
+ *
+ * @param charsetName the charset name
+ */
+ public void setCharsetName(String charsetName) {
+ this.charsetName = charsetName;
+ }
- /**
- * The charset used when a message must be converted
- * into a raw byte array. Default is UTF-8.
- *
- * @param charsetName the charset name
- */
- public void setCharsetName(String charsetName) {
- this.charsetName = charsetName;
- }
+ /**
+ * Sets the provider name of the specific implementation requested (e.g.,
+ * "BC" for BouncyCastle, "SunJCE" for the default Sun JCE provider).
+ *
+ * @param provider the provider to set
+ */
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
- /**
- * Sets the encryption/decryption mode.
- *
- * @param mode the encryption/decryption mode
- */
- public void setMode(Mode mode) {
- this.mode = mode;
- }
+ /**
+ * Sets the encryption/decryption mode.
+ *
+ * @param mode the encryption/decryption mode
+ */
+ public void setMode(Mode mode) {
+ this.mode = mode;
+ }
- /**
- * Sets the encryption key.
- *
- * @param key the encryption key
- */
- public void setKey(Key key) {
- this.key = key;
- }
+ /**
+ * Sets the encryption key.
+ *
+ * @param key the encryption key
+ */
+ public void setKey(Key key) {
+ this.key = key;
+ }
- /**
- * Encrypts/decrypts a message based on the underlying mode of operation.
- *
- * @param message if in encryption mode, the clear-text message, otherwise
- * the base64 encoded message to decrypt
- * @return if in encryption mode, the base64 encoded encrypted message,
- * otherwise the decrypted message
- * @throws AsymmetricEncryptionException on runtime errors
- * @see #setMode(Mode)
- */
- public String encrypt(String message) {
- try {
- final Cipher cipher = Cipher.getInstance(algorithm);
- switch (mode) {
- case ENCRYPT:
- final byte[] messageAsByteArray = message.getBytes(charsetName);
- cipher.init(Cipher.ENCRYPT_MODE, key);
- return Base64.encodeBase64String(cipher.doFinal(messageAsByteArray));
- case DECRYPT:
- final byte[] encryptedMessage = Base64.decodeBase64(message);
- cipher.init(Cipher.DECRYPT_MODE, key);
- return new String(cipher.doFinal(encryptedMessage), charsetName);
- default:
- return null;
- }
- } catch (Exception e) {
- throw new AsymmetricEncryptionException("error encrypting/decrypting message; mode=" + mode, e);
- }
- }
+ /**
+ * Encrypts/decrypts a message based on the underlying mode of operation.
+ *
+ * @param message if in encryption mode, the clear-text message, otherwise
+ * the base64 encoded message to decrypt
+ * @return if in encryption mode, the base64 encoded encrypted message,
+ * otherwise the decrypted message
+ * @throws AsymmetricEncryptionException on runtime errors
+ * @see #setMode(Mode)
+ */
+ public String encrypt(String message) {
+ try {
+ final Cipher cipher = (((provider == null) || (provider.length() == 0)) ? Cipher.getInstance(algorithm) : Cipher
+ .getInstance(algorithm, provider));
+ switch (mode) {
+ case ENCRYPT:
+ final byte[] messageAsByteArray = message.getBytes(charsetName);
+ cipher.init(Cipher.ENCRYPT_MODE, key);
+ return Base64.encodeBase64String(cipher.doFinal(messageAsByteArray));
+ case DECRYPT:
+ final byte[] encryptedMessage = Base64.decodeBase64(message);
+ cipher.init(Cipher.DECRYPT_MODE, key);
+ return new String(cipher.doFinal(encryptedMessage), charsetName);
+ default:
+ return null;
+ }
+ } catch (Exception e) {
+ throw new AsymmetricEncryptionException("error encrypting/decrypting message; mode=" + mode, e);
+ }
+ }
}
@@ -1,99 +1,113 @@
package com.google.code.springcryptoutils.core.cipher.asymmetric;
-import com.google.code.springcryptoutils.core.cipher.Mode;
-import org.apache.commons.codec.binary.Base64;
-
-import javax.crypto.Cipher;
import java.security.Key;
import java.util.Map;
+import javax.crypto.Cipher;
+
+import org.apache.commons.codec.binary.Base64;
+
+import com.google.code.springcryptoutils.core.cipher.Mode;
+
/**
* The default implementation for performing asymmetric encryption/decryption
* with base64 encoded strings and keys which are mapped with a logical name.
- *
+ *
* @author Mirko Caserta (mirko.caserta@gmail.com)
*/
public class Base64EncodedCiphererWithChooserByKeyIdImpl implements Base64EncodedCiphererWithChooserByKeyId {
- private String algorithm = "RSA";
- private String charsetName = "UTF-8";
- private Mode mode;
-
- private Map<String, Key> keyMap;
-
- /**
- * The asymmetric key algorithm. The default is RSA.
- *
- * @param algorithm the asymmetric key algorithm
- */
- public void setAlgorithm(String algorithm) {
- this.algorithm = algorithm;
- }
-
- /**
- * The charset used when a message must be converted
- * into a raw byte array. Default is UTF-8.
- *
- * @param charsetName the charset name
- */
- public void setCharsetName(String charsetName) {
- this.charsetName = charsetName;
- }
-
- /**
- * Sets the encryption/decryption mode.
- *
- * @param mode the encryption/decryption mode
- */
- public void setMode(Mode mode) {
- this.mode = mode;
- }
-
- /**
- * Sets the map of keys. The map key is a string representing the
- * logical name of the key (the keyId).
- *
- * @param keyMap the key map
- */
- public void setKeyMap(Map<String, Key> keyMap) {
- this.keyMap = keyMap;
- }
-
- /**
- * Encrypts/decrypts a message based on the underlying mode of operation.
- *
- * @param keyId the key id
- * @param message if in encryption mode, the clear-text message, otherwise
- * the base64 encoded message to decrypt
- * @return if in encryption mode, the base64 encoded encrypted message,
- * otherwise the decrypted message
- * @throws AsymmetricEncryptionException on runtime errors
- * @see #setMode(Mode)
- */
- public String encrypt(String keyId, String message) {
- final Key key = keyMap.get(keyId);
-
- if (key == null) {
- throw new AsymmetricEncryptionException("key not found: keyId=" + keyId);
- }
-
- try {
- final Cipher cipher = Cipher.getInstance(algorithm);
- switch (mode) {
- case ENCRYPT:
- final byte[] messageAsByteArray = message.getBytes(charsetName);
- cipher.init(Cipher.ENCRYPT_MODE, key);
- return Base64.encodeBase64String(cipher.doFinal(messageAsByteArray));
- case DECRYPT:
- final byte[] encryptedMessage = Base64.decodeBase64(message);
- cipher.init(Cipher.DECRYPT_MODE, key);
- return new String(cipher.doFinal(encryptedMessage), charsetName);
- default:
- return null;
- }
- } catch (Exception e) {
- throw new AsymmetricEncryptionException("error encrypting/decrypting message; mode=" + mode, e);
- }
- }
+ private String algorithm = "RSA";
+ private String charsetName = "UTF-8";
+ private String provider;
+ private Mode mode;
+
+ private Map<String, Key> keyMap;
+
+ /**
+ * The asymmetric key algorithm. The default is RSA.
+ *
+ * @param algorithm the asymmetric key algorithm
+ */
+ public void setAlgorithm(String algorithm) {
+ this.algorithm = algorithm;
+ }
+
+ /**
+ * The charset used when a message must be converted into a raw byte array.
+ * Default is UTF-8.
+ *
+ * @param charsetName the charset name
+ */
+ public void setCharsetName(String charsetName) {
+ this.charsetName = charsetName;
+ }
+
+ /**
+ * Sets the provider name of the specific implementation requested (e.g.,
+ * "BC" for BouncyCastle, "SunJCE" for the default Sun JCE provider).
+ *
+ * @param provider the provider to set
+ */
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ /**
+ * Sets the encryption/decryption mode.
+ *
+ * @param mode the encryption/decryption mode
+ */
+ public void setMode(Mode mode) {
+ this.mode = mode;
+ }
+
+ /**
+ * Sets the map of keys. The map key is a string representing the logical
+ * name of the key (the keyId).
+ *
+ * @param keyMap the key map
+ */
+ public void setKeyMap(Map<String, Key> keyMap) {
+ this.keyMap = keyMap;
+ }
+
+ /**
+ * Encrypts/decrypts a message based on the underlying mode of operation.
+ *
+ * @param keyId the key id
+ * @param message if in encryption mode, the clear-text message, otherwise
+ * the base64 encoded message to decrypt
+ * @return if in encryption mode, the base64 encoded encrypted message,
+ * otherwise the decrypted message
+ * @throws AsymmetricEncryptionException on runtime errors
+ * @see #setMode(Mode)
+ */
+ public String encrypt(String keyId, String message) {
+ final Key key = keyMap.get(keyId);
+
+ if (key == null) {
+ throw new AsymmetricEncryptionException("key not found: keyId=" + keyId);
+ }
+
+ try {
+ final Cipher cipher = (((provider == null) || (provider.length() == 0)) ? Cipher.getInstance(algorithm) : Cipher
+ .getInstance(algorithm, provider));
+ switch (mode) {
+ case ENCRYPT:
+ final byte[] messageAsByteArray = message.getBytes(charsetName);
+ cipher.init(Cipher.ENCRYPT_MODE, key);
+ return Base64.encodeBase64String(cipher.doFinal(messageAsByteArray));
+ case DECRYPT:
+ final byte[] encryptedMessage = Base64.decodeBase64(message);
+ cipher.init(Cipher.DECRYPT_MODE, key);
+ return new String(cipher.doFinal(encryptedMessage), charsetName);
+ default:
+ return null;
+ }
+ } catch (Exception e) {
+ throw new AsymmetricEncryptionException("error encrypting/decrypting message; mode=" + mode, e);
+ }
+ }
}
Oops, something went wrong.

0 comments on commit 15f305e

Please sign in to comment.