You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/08/05 16:11:28 UTC
[commons-crypto] branch master updated: Use try-with-resources.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-crypto.git
The following commit(s) were added to refs/heads/master by this push:
new 4d6b04d Use try-with-resources.
4d6b04d is described below
commit 4d6b04da5d11cad4011e73542aa1536334684cb1
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 5 12:11:20 2020 -0400
Use try-with-resources.
---
src/main/java/org/apache/commons/crypto/Crypto.java | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java b/src/main/java/org/apache/commons/crypto/Crypto.java
index dd5cbba..c28cab5 100644
--- a/src/main/java/org/apache/commons/crypto/Crypto.java
+++ b/src/main/java/org/apache/commons/crypto/Crypto.java
@@ -22,7 +22,9 @@ import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
+import org.apache.commons.crypto.cipher.CryptoCipher;
import org.apache.commons.crypto.cipher.CryptoCipherFactory;
+import org.apache.commons.crypto.random.CryptoRandom;
import org.apache.commons.crypto.random.CryptoRandomFactory;
/**
@@ -122,8 +124,9 @@ public final class Crypto {
}
/**
- * The Main of Crypto
- * @param args don't use the args
+ * The Main of Crypto.
+ *
+ * @param args Not used.
* @throws Exception if getCryptoRandom or getCryptoCipher get error.
*/
public static void main(final String args[]) throws Exception {
@@ -137,14 +140,16 @@ public final class Crypto {
{
final Properties props = new Properties();
props.setProperty(CryptoRandomFactory.CLASSES_KEY, CryptoRandomFactory.RandomProvider.OPENSSL.getClassName());
- CryptoRandomFactory.getCryptoRandom(props);
- System.out.println("Random instance created OK");
+ try (CryptoRandom cryptoRandom = CryptoRandomFactory.getCryptoRandom(props)){
+ System.out.println("Random instance created OK");
+ }
}
{
final Properties props = new Properties();
props.setProperty(CryptoCipherFactory.CLASSES_KEY, CryptoCipherFactory.CipherProvider.OPENSSL.getClassName());
- CryptoCipherFactory.getCryptoCipher("AES/CTR/NoPadding", props);
- System.out.println("Cipher instance created OK");
+ try (CryptoCipher cryptoCipher = CryptoCipherFactory.getCryptoCipher("AES/CTR/NoPadding", props)) {
+ System.out.println("Cipher instance created OK");
+ }
}
System.out.println("Additional OpenSSL_version(n) details:");
for(int j=1;j<6;j++) {