Skip to content
Merged

Dev #321

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.UUID;

import org.junit.BeforeClass;
import org.junit.Test;

import com.microsoft.windowsazure.services.core.ServiceException;
Expand Down Expand Up @@ -118,6 +119,11 @@ private void verifyContentKeyProperties(String message, String id, ContentKeyTyp
assertEquals(message + " Checksum", checksum, actual.getChecksum());
}

@BeforeClass
public static void Setup() {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
}

@Test
public void canCreateContentKey() throws Exception {
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.InputStream;
import java.math.BigInteger;
import java.net.URL;
import java.net.URLDecoder;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
Expand Down Expand Up @@ -147,15 +148,16 @@ public void uploadAesProtectedAssetAndDownloadSuccess() throws Exception {
}

@Test
public void encryptedContentCanBeDecrypted() throws Exception {
public void testEncryptedContentCanBeDecrypted() throws Exception {
byte[] aesKey = new byte[32];
for (int i = 0; i < 32; i++) {
aesKey[i] = 1;
}
URL serverCertificateUri = getClass().getResource("/certificate/server.crt");
X509Certificate x509Certificate = EncryptionHelper.loadX509Certificate(serverCertificateUri.getFile());
X509Certificate x509Certificate = EncryptionHelper.loadX509Certificate(URLDecoder.decode(
serverCertificateUri.getFile(), "UTF-8"));
URL serverPrivateKey = getClass().getResource("/certificate/server.der");
PrivateKey privateKey = EncryptionHelper.getPrivateKey(serverPrivateKey.getFile());
PrivateKey privateKey = EncryptionHelper.getPrivateKey(URLDecoder.decode(serverPrivateKey.getFile(), "UTF-8"));
byte[] encryptedAesKey = EncryptionHelper.encryptSymmetricKey(x509Certificate, aesKey);
byte[] decryptedAesKey = EncryptionHelper.decryptSymmetricKey(encryptedAesKey, privateKey);

Expand All @@ -168,9 +170,10 @@ public void testEncryptedContentCanBeDecryptedUsingPreGeneratedKeyPair() throws
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA1AndMGF1Padding", "BC");
SecureRandom random = new SecureRandom();
URL serverCertificateUri = getClass().getResource("/certificate/server.crt");
X509Certificate x509Certificate = EncryptionHelper.loadX509Certificate(serverCertificateUri.getFile());
X509Certificate x509Certificate = EncryptionHelper.loadX509Certificate(URLDecoder.decode(
serverCertificateUri.getFile(), "UTF-8"));
URL serverPrivateKey = getClass().getResource("/certificate/server.der");
PrivateKey privateKey = EncryptionHelper.getPrivateKey(serverPrivateKey.getFile());
PrivateKey privateKey = EncryptionHelper.getPrivateKey(URLDecoder.decode(serverPrivateKey.getFile(), "UTF-8"));
Key pubKey = x509Certificate.getPublicKey();
cipher.init(Cipher.ENCRYPT_MODE, pubKey, random);
byte[] cipherText = cipher.doFinal(input);
Expand Down