summaryrefslogtreecommitdiffstats
path: root/bcprov/src/main/java/org/bouncycastle/jce/provider/test/SlotTwoTest.java
diff options
context:
space:
mode:
authorSergio Giro <sgiro@google.com>2016-02-01 18:54:35 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2016-02-01 18:54:35 +0000
commit3e75bd6b407dd472c834a50f16aae54cca67ea9c (patch)
treeb5eb091b97b2aade28e5b45a15352125a4a776d7 /bcprov/src/main/java/org/bouncycastle/jce/provider/test/SlotTwoTest.java
parent9218edabd1ef9852bc2f13115dcadc81b442dd6c (diff)
parentc1040cb5656c3299f1c2d0fe0bd7c44b10466aaf (diff)
downloadandroid_external_bouncycastle-3e75bd6b407dd472c834a50f16aae54cca67ea9c.tar.gz
android_external_bouncycastle-3e75bd6b407dd472c834a50f16aae54cca67ea9c.tar.bz2
android_external_bouncycastle-3e75bd6b407dd472c834a50f16aae54cca67ea9c.zip
Merge "Restoring the contents of aosp after"
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/jce/provider/test/SlotTwoTest.java')
-rw-r--r--bcprov/src/main/java/org/bouncycastle/jce/provider/test/SlotTwoTest.java90
1 files changed, 0 insertions, 90 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/jce/provider/test/SlotTwoTest.java b/bcprov/src/main/java/org/bouncycastle/jce/provider/test/SlotTwoTest.java
deleted file mode 100644
index 7a2a880..0000000
--- a/bcprov/src/main/java/org/bouncycastle/jce/provider/test/SlotTwoTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package org.bouncycastle.jce.provider.test;
-
-import java.security.Key;
-import java.security.SecureRandom;
-import java.security.Security;
-
-import javax.crypto.Cipher;
-import javax.crypto.KeyGenerator;
-import javax.crypto.spec.IvParameterSpec;
-
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.bouncycastle.util.test.SimpleTest;
-
-public class SlotTwoTest
- extends SimpleTest
-{
- byte[] plainData = "abcdefghijklmnopqrstuvwxyz".getBytes();
-
- public String getName()
- {
- return "SlotTwo";
- }
-
- public void performTest()
- throws Exception
- {
- Security.removeProvider("BC");
- Security.insertProviderAt(new BouncyCastleProvider(), 2);
-
- KeyGenerator keyGen = KeyGenerator.getInstance("DESede", "BC");
-
- keyGen.init(new SecureRandom());
-
- Key key = keyGen.generateKey();
-
- testDesEde(key, "ECB", "PKCS7Padding");
- testDesEde(key, "CBC", "PKCS7Padding");
- testDesEde(key, "CTR", "NoPadding");
- testDesEde(key, "CTR", "PKCS7Padding");
- testDesEde(key, "OFB", "PKCS7Padding");
- testDesEde(key, "CFB", "PKCS7Padding");
-
- Security.removeProvider("BC");
- Security.addProvider(new BouncyCastleProvider());
- }
-
- private void testDesEde(
- Key key,
- String mode,
- String padding)
- throws Exception
- {
- Cipher encrypt = Cipher.getInstance("DESede/" + mode + "/" + padding, "BC");
- Cipher decrypt = Cipher.getInstance("DESede/" + mode + "/" + padding);
-
- if (!decrypt.getProvider().getName().equals("BC"))
- {
- fail("BC provider not returned for DESede/" + mode + "/" + padding + " got " + decrypt.getProvider().getName());
- }
-
- encrypt.init(Cipher.ENCRYPT_MODE, key);
-
- byte[] encryptedBytes = encrypt.doFinal(plainData);
- byte[] ivBytes = encrypt.getIV();
-
- if (ivBytes != null)
- {
- IvParameterSpec ivp = new IvParameterSpec(ivBytes);
-
- decrypt.init(Cipher.DECRYPT_MODE, key, ivp);
- }
- else
- {
- decrypt.init(Cipher.DECRYPT_MODE, key);
- }
-
- byte[] plainBytes = decrypt.doFinal(encryptedBytes, 0, encryptedBytes.length);
-
- if (!areEqual(plainData, plainBytes))
- {
- fail("decryption test failed.");
- }
- }
-
- public static void main(
- String[] args)
- {
- runTest(new SlotTwoTest());
- }
-}