Merge pull request #7567 from sjmillington/library-move-pt-3
[BAEL-16005] - Library move pt 3
This commit is contained in:
commit
368f37ebf3
|
@ -25,6 +25,11 @@
|
|||
<artifactId>spring-security-oauth2</artifactId>
|
||||
<version>${spring-security-oauth2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.scribejava</groupId>
|
||||
|
@ -37,7 +42,16 @@
|
|||
<artifactId>tink</artifactId>
|
||||
<version>${tink.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>${bouncycastle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk15on</artifactId>
|
||||
<version>${bouncycastle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -54,6 +68,11 @@
|
|||
<artifactId>cryptacular</artifactId>
|
||||
<version>${cryptacular.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jasypt</groupId>
|
||||
<artifactId>jasypt</artifactId>
|
||||
<version>${jasypt.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
@ -63,5 +82,8 @@
|
|||
<passay.version>1.3.1</passay.version>
|
||||
<tink.version>1.2.2</tink.version>
|
||||
<cryptacular.version>1.2.2</cryptacular.version>
|
||||
<jasypt.version>1.9.2</jasypt.version>
|
||||
<bouncycastle.version>1.58</bouncycastle.version>
|
||||
<spring.version>4.3.8.RELEASE</spring.version>
|
||||
</properties>
|
||||
</project>
|
||||
|
|
|
@ -1,105 +1,105 @@
|
|||
package com.baeldung.bouncycastle;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bouncycastle.asn1.ASN1InputStream;
|
||||
import org.bouncycastle.asn1.cms.ContentInfo;
|
||||
import org.bouncycastle.cert.X509CertificateHolder;
|
||||
import org.bouncycastle.cert.jcajce.JcaCertStore;
|
||||
import org.bouncycastle.cms.CMSAlgorithm;
|
||||
import org.bouncycastle.cms.CMSEnvelopedData;
|
||||
import org.bouncycastle.cms.CMSEnvelopedDataGenerator;
|
||||
import org.bouncycastle.cms.CMSException;
|
||||
import org.bouncycastle.cms.CMSProcessableByteArray;
|
||||
import org.bouncycastle.cms.CMSSignedData;
|
||||
import org.bouncycastle.cms.CMSSignedDataGenerator;
|
||||
import org.bouncycastle.cms.CMSTypedData;
|
||||
import org.bouncycastle.cms.KeyTransRecipientInformation;
|
||||
import org.bouncycastle.cms.RecipientInformation;
|
||||
import org.bouncycastle.cms.SignerInformation;
|
||||
import org.bouncycastle.cms.SignerInformationStore;
|
||||
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder;
|
||||
import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoVerifierBuilder;
|
||||
import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder;
|
||||
import org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient;
|
||||
import org.bouncycastle.cms.jcajce.JceKeyTransRecipient;
|
||||
import org.bouncycastle.cms.jcajce.JceKeyTransRecipientInfoGenerator;
|
||||
import org.bouncycastle.operator.ContentSigner;
|
||||
import org.bouncycastle.operator.OperatorCreationException;
|
||||
import org.bouncycastle.operator.OutputEncryptor;
|
||||
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
||||
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder;
|
||||
import org.bouncycastle.util.Store;
|
||||
|
||||
public class BouncyCastleCrypto {
|
||||
|
||||
public static byte[] signData(byte[] data, final X509Certificate signingCertificate, final PrivateKey signingKey) throws CertificateEncodingException, OperatorCreationException, CMSException, IOException {
|
||||
byte[] signedMessage = null;
|
||||
List<X509Certificate> certList = new ArrayList<X509Certificate>();
|
||||
CMSTypedData cmsData = new CMSProcessableByteArray(data);
|
||||
certList.add(signingCertificate);
|
||||
Store certs = new JcaCertStore(certList);
|
||||
CMSSignedDataGenerator cmsGenerator = new CMSSignedDataGenerator();
|
||||
ContentSigner contentSigner = new JcaContentSignerBuilder("SHA256withRSA").build(signingKey);
|
||||
cmsGenerator.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().setProvider("BC").build()).build(contentSigner, signingCertificate));
|
||||
cmsGenerator.addCertificates(certs);
|
||||
CMSSignedData cms = cmsGenerator.generate(cmsData, true);
|
||||
signedMessage = cms.getEncoded();
|
||||
return signedMessage;
|
||||
}
|
||||
|
||||
public static boolean verifSignData(final byte[] signedData) throws CMSException, IOException, OperatorCreationException, CertificateException {
|
||||
ByteArrayInputStream bIn = new ByteArrayInputStream(signedData);
|
||||
ASN1InputStream aIn = new ASN1InputStream(bIn);
|
||||
CMSSignedData s = new CMSSignedData(ContentInfo.getInstance(aIn.readObject()));
|
||||
aIn.close();
|
||||
bIn.close();
|
||||
Store certs = s.getCertificates();
|
||||
SignerInformationStore signers = s.getSignerInfos();
|
||||
Collection<SignerInformation> c = signers.getSigners();
|
||||
SignerInformation signer = c.iterator().next();
|
||||
Collection<X509CertificateHolder> certCollection = certs.getMatches(signer.getSID());
|
||||
Iterator<X509CertificateHolder> certIt = certCollection.iterator();
|
||||
X509CertificateHolder certHolder = certIt.next();
|
||||
boolean verifResult = signer.verify(new JcaSimpleSignerInfoVerifierBuilder().build(certHolder));
|
||||
if (!verifResult) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static byte[] encryptData(final byte[] data, X509Certificate encryptionCertificate) throws CertificateEncodingException, CMSException, IOException {
|
||||
byte[] encryptedData = null;
|
||||
if (null != data && null != encryptionCertificate) {
|
||||
CMSEnvelopedDataGenerator cmsEnvelopedDataGenerator = new CMSEnvelopedDataGenerator();
|
||||
JceKeyTransRecipientInfoGenerator jceKey = new JceKeyTransRecipientInfoGenerator(encryptionCertificate);
|
||||
cmsEnvelopedDataGenerator.addRecipientInfoGenerator(jceKey);
|
||||
CMSTypedData msg = new CMSProcessableByteArray(data);
|
||||
OutputEncryptor encryptor = new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider("BC").build();
|
||||
CMSEnvelopedData cmsEnvelopedData = cmsEnvelopedDataGenerator.generate(msg, encryptor);
|
||||
encryptedData = cmsEnvelopedData.getEncoded();
|
||||
}
|
||||
return encryptedData;
|
||||
}
|
||||
|
||||
public static byte[] decryptData(final byte[] encryptedData, final PrivateKey decryptionKey) throws CMSException {
|
||||
byte[] decryptedData = null;
|
||||
if (null != encryptedData && null != decryptionKey) {
|
||||
CMSEnvelopedData envelopedData = new CMSEnvelopedData(encryptedData);
|
||||
Collection<RecipientInformation> recip = envelopedData.getRecipientInfos().getRecipients();
|
||||
KeyTransRecipientInformation recipientInfo = (KeyTransRecipientInformation) recip.iterator().next();
|
||||
JceKeyTransRecipient recipient = new JceKeyTransEnvelopedRecipient(decryptionKey);
|
||||
decryptedData = recipientInfo.getContent(recipient);
|
||||
}
|
||||
return decryptedData;
|
||||
}
|
||||
}
|
||||
package com.baeldung.bouncycastle;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bouncycastle.asn1.ASN1InputStream;
|
||||
import org.bouncycastle.asn1.cms.ContentInfo;
|
||||
import org.bouncycastle.cert.X509CertificateHolder;
|
||||
import org.bouncycastle.cert.jcajce.JcaCertStore;
|
||||
import org.bouncycastle.cms.CMSAlgorithm;
|
||||
import org.bouncycastle.cms.CMSEnvelopedData;
|
||||
import org.bouncycastle.cms.CMSEnvelopedDataGenerator;
|
||||
import org.bouncycastle.cms.CMSException;
|
||||
import org.bouncycastle.cms.CMSProcessableByteArray;
|
||||
import org.bouncycastle.cms.CMSSignedData;
|
||||
import org.bouncycastle.cms.CMSSignedDataGenerator;
|
||||
import org.bouncycastle.cms.CMSTypedData;
|
||||
import org.bouncycastle.cms.KeyTransRecipientInformation;
|
||||
import org.bouncycastle.cms.RecipientInformation;
|
||||
import org.bouncycastle.cms.SignerInformation;
|
||||
import org.bouncycastle.cms.SignerInformationStore;
|
||||
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder;
|
||||
import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoVerifierBuilder;
|
||||
import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder;
|
||||
import org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient;
|
||||
import org.bouncycastle.cms.jcajce.JceKeyTransRecipient;
|
||||
import org.bouncycastle.cms.jcajce.JceKeyTransRecipientInfoGenerator;
|
||||
import org.bouncycastle.operator.ContentSigner;
|
||||
import org.bouncycastle.operator.OperatorCreationException;
|
||||
import org.bouncycastle.operator.OutputEncryptor;
|
||||
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
||||
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder;
|
||||
import org.bouncycastle.util.Store;
|
||||
|
||||
public class BouncyCastleCrypto {
|
||||
|
||||
public static byte[] signData(byte[] data, final X509Certificate signingCertificate, final PrivateKey signingKey) throws CertificateEncodingException, OperatorCreationException, CMSException, IOException {
|
||||
byte[] signedMessage = null;
|
||||
List<X509Certificate> certList = new ArrayList<X509Certificate>();
|
||||
CMSTypedData cmsData = new CMSProcessableByteArray(data);
|
||||
certList.add(signingCertificate);
|
||||
Store certs = new JcaCertStore(certList);
|
||||
CMSSignedDataGenerator cmsGenerator = new CMSSignedDataGenerator();
|
||||
ContentSigner contentSigner = new JcaContentSignerBuilder("SHA256withRSA").build(signingKey);
|
||||
cmsGenerator.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().setProvider("BC").build()).build(contentSigner, signingCertificate));
|
||||
cmsGenerator.addCertificates(certs);
|
||||
CMSSignedData cms = cmsGenerator.generate(cmsData, true);
|
||||
signedMessage = cms.getEncoded();
|
||||
return signedMessage;
|
||||
}
|
||||
|
||||
public static boolean verifSignData(final byte[] signedData) throws CMSException, IOException, OperatorCreationException, CertificateException {
|
||||
ByteArrayInputStream bIn = new ByteArrayInputStream(signedData);
|
||||
ASN1InputStream aIn = new ASN1InputStream(bIn);
|
||||
CMSSignedData s = new CMSSignedData(ContentInfo.getInstance(aIn.readObject()));
|
||||
aIn.close();
|
||||
bIn.close();
|
||||
Store certs = s.getCertificates();
|
||||
SignerInformationStore signers = s.getSignerInfos();
|
||||
Collection<SignerInformation> c = signers.getSigners();
|
||||
SignerInformation signer = c.iterator().next();
|
||||
Collection<X509CertificateHolder> certCollection = certs.getMatches(signer.getSID());
|
||||
Iterator<X509CertificateHolder> certIt = certCollection.iterator();
|
||||
X509CertificateHolder certHolder = certIt.next();
|
||||
boolean verifResult = signer.verify(new JcaSimpleSignerInfoVerifierBuilder().build(certHolder));
|
||||
if (!verifResult) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static byte[] encryptData(final byte[] data, X509Certificate encryptionCertificate) throws CertificateEncodingException, CMSException, IOException {
|
||||
byte[] encryptedData = null;
|
||||
if (null != data && null != encryptionCertificate) {
|
||||
CMSEnvelopedDataGenerator cmsEnvelopedDataGenerator = new CMSEnvelopedDataGenerator();
|
||||
JceKeyTransRecipientInfoGenerator jceKey = new JceKeyTransRecipientInfoGenerator(encryptionCertificate);
|
||||
cmsEnvelopedDataGenerator.addRecipientInfoGenerator(jceKey);
|
||||
CMSTypedData msg = new CMSProcessableByteArray(data);
|
||||
OutputEncryptor encryptor = new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider("BC").build();
|
||||
CMSEnvelopedData cmsEnvelopedData = cmsEnvelopedDataGenerator.generate(msg, encryptor);
|
||||
encryptedData = cmsEnvelopedData.getEncoded();
|
||||
}
|
||||
return encryptedData;
|
||||
}
|
||||
|
||||
public static byte[] decryptData(final byte[] encryptedData, final PrivateKey decryptionKey) throws CMSException {
|
||||
byte[] decryptedData = null;
|
||||
if (null != encryptedData && null != decryptionKey) {
|
||||
CMSEnvelopedData envelopedData = new CMSEnvelopedData(encryptedData);
|
||||
Collection<RecipientInformation> recip = envelopedData.getRecipientInfos().getRecipients();
|
||||
KeyTransRecipientInformation recipientInfo = (KeyTransRecipientInformation) recip.iterator().next();
|
||||
JceKeyTransRecipient recipient = new JceKeyTransEnvelopedRecipient(decryptionKey);
|
||||
decryptedData = recipientInfo.getContent(recipient);
|
||||
}
|
||||
return decryptedData;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDPjCCAiagAwIBAgIJAPvd1gx14C3CMA0GCSqGSIb3DQEBBQUAMEcxCzAJBgNV
|
||||
BAYTAk1BMRAwDgYDVQQIEwdNb3JvY2NvMRMwEQYDVQQHEwpDYXNhYmxhbmNhMREw
|
||||
DwYDVQQDEwhCYWVsZHVuZzAeFw0xNzEwMTIxMDQzMTRaFw0yNzEwMTMxMDQzMTRa
|
||||
MEcxCzAJBgNVBAYTAk1BMRAwDgYDVQQIEwdNb3JvY2NvMRMwEQYDVQQHEwpDYXNh
|
||||
YmxhbmNhMREwDwYDVQQDEwhCYWVsZHVuZzCCASIwDQYJKoZIhvcNAQEBBQADggEP
|
||||
ADCCAQoCggEBAMyi5GmOeN4QaH/CP5gSOyHX8znb5TDHWV8wc+ZT7kNU8zt5tGMh
|
||||
jozK6hax155/6tOsBDR0rSYBhL+Dm/+uCVS7qOlRHhf6cNGtzGF1gnNJB2WjI8oM
|
||||
AYm24xpLj1WphKUwKrn3nTMPnQup5OoNAMYl99flANrRYVjjxrLQvDZDUio6Iujr
|
||||
CZ2TtXGM0g/gP++28KT7g1KlUui3xtB0u33wx7UN8Fix3JmjOaPHGwxGpwP3VGSj
|
||||
fs8cuhqVwRQaZpCOoHU/P8wpXKw80sSdhz+SRueMPtVYqK0CiLL5/O0h0Y3le4IV
|
||||
whgg3KG1iTGOWn60UMFn1EYmQ18k5Nsma6UCAwEAAaMtMCswCQYDVR0TBAIwADAR
|
||||
BglghkgBhvhCAQEEBAMCBPAwCwYDVR0PBAQDAgUgMA0GCSqGSIb3DQEBBQUAA4IB
|
||||
AQC8DDBmJ3p4xytxBiE0s4p1715WT6Dm/QJHp0XC0hkSoyZKDh+XVmrzm+J3SiW1
|
||||
vpswb5hLgPo040YX9jnDmgOD+TpleTuKHxZRYj92UYWmdjkWLVtFMcvOh+gxBiAP
|
||||
pHIqZsqo8lfcyAuh8Jx834IXbknfCUtERDLG/rU9P/3XJhrM2GC5qPQznrW4EYhU
|
||||
CGPyIJXmvATMVvXMWCtfogAL+n42vjYXQXZoAWomHhLHoNbSJUErnNdWDOh4WoJt
|
||||
XJCxA6U5LSBplqb3wB2hUTqw+0admKltvmy+KA1PD7OxoGiY7V544zeGqJam1qxU
|
||||
ia7y5BL6uOa/4ShSV8pcJDYz
|
||||
-----END CERTIFICATE-----
|
|
@ -1,50 +1,50 @@
|
|||
package com.baeldung.bouncycastle;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Security;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import org.bouncycastle.cms.CMSException;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.operator.OperatorCreationException;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BouncyCastleLiveTest {
|
||||
|
||||
String certificatePath = "src/main/resources/Baeldung.cer";
|
||||
String privateKeyPath = "src/main/resources/Baeldung.p12";
|
||||
char[] p12Password = "password".toCharArray();
|
||||
char[] keyPassword = "password".toCharArray();
|
||||
|
||||
@Test
|
||||
public void givenCryptographicResource_whenOperationSuccess_returnTrue() throws CertificateException, NoSuchProviderException, NoSuchAlgorithmException, IOException, KeyStoreException, UnrecoverableKeyException, CMSException, OperatorCreationException {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
|
||||
CertificateFactory certFactory = CertificateFactory.getInstance("X.509", "BC");
|
||||
X509Certificate certificate = (X509Certificate) certFactory.generateCertificate(new FileInputStream(certificatePath));
|
||||
KeyStore keystore = KeyStore.getInstance("PKCS12");
|
||||
keystore.load(new FileInputStream(privateKeyPath), p12Password);
|
||||
PrivateKey privateKey = (PrivateKey) keystore.getKey("baeldung", keyPassword);
|
||||
String secretMessage = "My password is 123456Seven";
|
||||
System.out.println("Original Message : " + secretMessage);
|
||||
byte[] stringToEncrypt = secretMessage.getBytes();
|
||||
byte[] encryptedData = BouncyCastleCrypto.encryptData(stringToEncrypt, certificate);
|
||||
byte[] rawData = BouncyCastleCrypto.decryptData(encryptedData, privateKey);
|
||||
String decryptedMessage = new String(rawData);
|
||||
assertTrue(decryptedMessage.equals(secretMessage));
|
||||
byte[] signedData = BouncyCastleCrypto.signData(rawData, certificate, privateKey);
|
||||
Boolean check = BouncyCastleCrypto.verifSignData(signedData);
|
||||
assertTrue(check);
|
||||
}
|
||||
}
|
||||
package com.baeldung.bouncycastle;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Security;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import org.bouncycastle.cms.CMSException;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.operator.OperatorCreationException;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BouncyCastleLiveTest {
|
||||
|
||||
String certificatePath = "src/main/resources/Baeldung.cer";
|
||||
String privateKeyPath = "src/main/resources/Baeldung.p12";
|
||||
char[] p12Password = "password".toCharArray();
|
||||
char[] keyPassword = "password".toCharArray();
|
||||
|
||||
@Test
|
||||
public void givenCryptographicResource_whenOperationSuccess_returnTrue() throws CertificateException, NoSuchProviderException, NoSuchAlgorithmException, IOException, KeyStoreException, UnrecoverableKeyException, CMSException, OperatorCreationException {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
|
||||
CertificateFactory certFactory = CertificateFactory.getInstance("X.509", "BC");
|
||||
X509Certificate certificate = (X509Certificate) certFactory.generateCertificate(new FileInputStream(certificatePath));
|
||||
KeyStore keystore = KeyStore.getInstance("PKCS12");
|
||||
keystore.load(new FileInputStream(privateKeyPath), p12Password);
|
||||
PrivateKey privateKey = (PrivateKey) keystore.getKey("baeldung", keyPassword);
|
||||
String secretMessage = "My password is 123456Seven";
|
||||
System.out.println("Original Message : " + secretMessage);
|
||||
byte[] stringToEncrypt = secretMessage.getBytes();
|
||||
byte[] encryptedData = BouncyCastleCrypto.encryptData(stringToEncrypt, certificate);
|
||||
byte[] rawData = BouncyCastleCrypto.decryptData(encryptedData, privateKey);
|
||||
String decryptedMessage = new String(rawData);
|
||||
assertTrue(decryptedMessage.equals(secretMessage));
|
||||
byte[] signedData = BouncyCastleCrypto.signData(rawData, certificate, privateKey);
|
||||
Boolean check = BouncyCastleCrypto.verifSignData(signedData);
|
||||
assertTrue(check);
|
||||
}
|
||||
}
|
|
@ -18,7 +18,9 @@ import org.junit.Test;
|
|||
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
public class TinkUnitTest {
|
||||
public class TinkLiveTest {
|
||||
|
||||
//need to download policy files and put them into ${java.home}/jre/lib/security/
|
||||
|
||||
private static final String PLAINTEXT = "BAELDUNG";
|
||||
private static final String DATA = "TINK";
|
|
@ -0,0 +1,8 @@
|
|||
### Relevant articles
|
||||
|
||||
- [Introduction to Serenity BDD](http://www.baeldung.com/serenity-bdd)
|
||||
- [Introduction to JSONassert](http://www.baeldung.com/jsonassert)
|
||||
- [Serenity BDD and Screenplay](http://www.baeldung.com/serenity-screenplay)
|
||||
- [Serenity BDD with Spring and JBehave](http://www.baeldung.com/serenity-spring-jbehave)
|
||||
- [Introduction to Awaitlity](http://www.baeldung.com/awaitlity-testing)
|
||||
- [Introduction to Hoverfly in Java](http://www.baeldung.com/hoverfly)
|
|
@ -0,0 +1,5 @@
|
|||
log4j.rootLogger=INFO, stdout
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
|
@ -0,0 +1,170 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>libraries-testing</artifactId>
|
||||
<name>libraries-testing</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-core</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctorj</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-junit</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-jbehave</artifactId>
|
||||
<version>${serenity.jbehave.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-rest-assured</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-jira-requirements-provider</artifactId>
|
||||
<version>${serenity.jira.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-spring</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-screenplay</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-screenplay-webdriver</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.skyscreamer</groupId>
|
||||
<artifactId>jsonassert</artifactId>
|
||||
<version>${jsonassert.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>${awaitility.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility-proxy</artifactId>
|
||||
<version>${awaitility.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.specto</groupId>
|
||||
<artifactId>hoverfly-java</artifactId>
|
||||
<version>${hoverfly-java.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>spring-mock-mvc</artifactId>
|
||||
<version>${spring-mock-mvc.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-core</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctorj</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||
<version>1.5.7.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>net.serenity-bdd.maven.plugins</groupId>
|
||||
<artifactId>serenity-maven-plugin</artifactId>
|
||||
<version>${serenity.plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>serenity-reports</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>aggregate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<serenity.version>1.9.26</serenity.version>
|
||||
<serenity.jbehave.version>1.41.0</serenity.jbehave.version>
|
||||
<serenity.jira.version>1.9.0</serenity.jira.version>
|
||||
<serenity.plugin.version>1.9.27</serenity.plugin.version>
|
||||
<jsonassert.version>1.5.0</jsonassert.version>
|
||||
<awaitility.version>3.0.0</awaitility.version>
|
||||
<hoverfly-java.version>0.8.1</hoverfly-java.version>
|
||||
<spring.version>4.3.8.RELEASE</spring.version>
|
||||
<spring-mock-mvc.version>3.0.3</spring-mock-mvc.version>
|
||||
<assertj.version>3.6.2</assertj.version>
|
||||
|
||||
</properties>
|
||||
</project>
|
|
@ -0,0 +1,4 @@
|
|||
jira.url=<jira-url>
|
||||
jira.project=<jira-project>
|
||||
jira.username=<jira-username>
|
||||
jira.password=<jira-password>
|
|
@ -1,24 +1,19 @@
|
|||
### Relevant articles
|
||||
|
||||
- [Intro to Jasypt](http://www.baeldung.com/jasypt)
|
||||
- [Introduction to Javatuples](http://www.baeldung.com/java-tuples)
|
||||
- [Introduction to Javassist](http://www.baeldung.com/javassist)
|
||||
- [Introduction to Apache Flink with Java](http://www.baeldung.com/apache-flink)
|
||||
- [Introduction to JSONassert](http://www.baeldung.com/jsonassert)
|
||||
- [Intro to JaVers](http://www.baeldung.com/javers)
|
||||
- [Introduction to Serenity BDD](http://www.baeldung.com/serenity-bdd)
|
||||
- [Merging Streams in Java](http://www.baeldung.com/java-merge-streams)
|
||||
- [Serenity BDD and Screenplay](http://www.baeldung.com/serenity-screenplay)
|
||||
- [Introduction to Quartz](http://www.baeldung.com/quartz)
|
||||
- [How to Warm Up the JVM](http://www.baeldung.com/java-jvm-warmup)
|
||||
- [Software Transactional Memory in Java Using Multiverse](http://www.baeldung.com/java-multiverse-stm)
|
||||
- [Serenity BDD with Spring and JBehave](http://www.baeldung.com/serenity-spring-jbehave)
|
||||
- [Locality-Sensitive Hashing in Java Using Java-LSH](http://www.baeldung.com/locality-sensitive-hashing)
|
||||
- [Introduction to Awaitlity](http://www.baeldung.com/awaitlity-testing)
|
||||
- [Introduction to Neuroph](http://www.baeldung.com/neuroph)
|
||||
- [Quick Guide to RSS with Rome](http://www.baeldung.com/rome-rss)
|
||||
- [Introduction to PCollections](http://www.baeldung.com/java-pcollections)
|
||||
- [Introduction to Hoverfly in Java](http://www.baeldung.com/hoverfly)
|
||||
- [Introduction to Eclipse Collections](http://www.baeldung.com/eclipse-collections)
|
||||
- [DistinctBy in the Java Stream API](http://www.baeldung.com/java-streams-distinct-by)
|
||||
- [Introduction to NoException](http://www.baeldung.com/no-exception)
|
||||
|
@ -29,10 +24,8 @@
|
|||
- [Using Pairs in Java](http://www.baeldung.com/java-pairs)
|
||||
- [Introduction to Caffeine](http://www.baeldung.com/java-caching-caffeine)
|
||||
- [Introduction to StreamEx](http://www.baeldung.com/streamex)
|
||||
- [Introduction to BouncyCastle with Java](http://www.baeldung.com/java-bouncy-castle)
|
||||
- [A Docker Guide for Java](http://www.baeldung.com/docker-java-api)
|
||||
- [Introduction to Akka Actors in Java](http://www.baeldung.com/akka-actors-java)
|
||||
- [Introduction to Akka Actors in Java](http://www.baeldung.com/akka-actors-java)
|
||||
- [A Guide to Byte Buddy](http://www.baeldung.com/byte-buddy)
|
||||
- [Introduction to jOOL](http://www.baeldung.com/jool)
|
||||
- [Consumer Driven Contracts with Pact](http://www.baeldung.com/pact-junit-consumer-driven-contracts)
|
||||
|
|
|
@ -46,11 +46,7 @@
|
|||
<artifactId>commons-net</artifactId>
|
||||
<version>${commons-net.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jasypt</groupId>
|
||||
<artifactId>jasypt</artifactId>
|
||||
<version>${jasypt.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.javatuples</groupId>
|
||||
<artifactId>javatuples</artifactId>
|
||||
|
@ -106,17 +102,17 @@
|
|||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-core</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctorj</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-core</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctorj</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-junit</artifactId>
|
||||
|
@ -438,16 +434,6 @@
|
|||
<artifactId>caffeine</artifactId>
|
||||
<version>${caffeine.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>${bouncycastle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk15on</artifactId>
|
||||
<version>${bouncycastle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.http-client</groupId>
|
||||
<artifactId>google-http-client</artifactId>
|
||||
|
@ -727,7 +713,6 @@
|
|||
<googleclient.version>1.23.0</googleclient.version>
|
||||
<multiverse.version>0.7.0</multiverse.version>
|
||||
<cglib.version>3.2.7</cglib.version>
|
||||
<jasypt.version>1.9.2</jasypt.version>
|
||||
<javatuples.version>1.2</javatuples.version>
|
||||
<javaassist.version>3.21.0-GA</javaassist.version>
|
||||
<assertj.version>3.6.2</assertj.version>
|
||||
|
@ -797,9 +782,7 @@
|
|||
<jdeferred.version>1.2.6</jdeferred.version>
|
||||
<functionaljava.version>4.8.1</functionaljava.version>
|
||||
<jgrapht.version>1.0.1</jgrapht.version>
|
||||
<bouncycastle.version>1.58</bouncycastle.version>
|
||||
<jersey.version>1.19.4</jersey.version>
|
||||
|
||||
<fugue.version>4.5.1</fugue.version>
|
||||
<maven-bundle-plugin.version>3.3.0</maven-bundle-plugin.version>
|
||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||
|
|
Loading…
Reference in New Issue