@Test
public void rebindContentKeyWithX509CertficateSuccess() throws Exception {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
byte[] aesKey = createTestAesKey();
ContentKeyInfo contentKeyInfo = createValidTestContentKeyWithAesKey(
"rebindContentKeyWithX509Success", aesKey);
URL serverCertificateUri = getClass().getResource(
"/certificate/server.crt");
X509Certificate x509Certificate = EncryptionHelper
.loadX509Certificate(URLDecoder.decode(
serverCertificateUri.getFile(), "UTF-8"));
URL serverPrivateKey = getClass()
.getResource("/certificate/server.der");
PrivateKey privateKey = EncryptionHelper.getPrivateKey(URLDecoder
.decode(serverPrivateKey.getFile(), "UTF-8"));
String rebindedContentKey = service.action(ContentKey.rebind(
contentKeyInfo.getId(), URLEncoder.encode(
Base64.encode(x509Certificate.getEncoded()), "UTF-8")));
byte[] decryptedAesKey = EncryptionHelper.decryptSymmetricKey(
rebindedContentKey, privateKey);
assertByteArrayEquals(aesKey, decryptedAesKey);
}