本文整理匯總了Java中javax.crypto.CipherSpi類的典型用法代碼示例。如果您正苦於以下問題:Java CipherSpi類的具體用法?Java CipherSpi怎麽用?Java CipherSpi使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CipherSpi類屬於javax.crypto包,在下文中一共展示了CipherSpi類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCipher
import javax.crypto.CipherSpi; //導入依賴的package包/類
/**
* Creates a {@link javax.crypto.Cipher} instance from a {@link javax.crypto.CipherSpi}.
*
* @param cipherSpi the {@link javax.cyrpto.CipherSpi} instance
* @param transformation the transformation cipherSpi was obtained for
* @return a {@link javax.crypto.Cipher} instance
* @throws Throwable in case of an error
*/
private static Cipher getCipher(final CipherSpi cipherSpi, final String transformation) throws Throwable {
//06-19 15:22:00.727: W/erverSocketPipelineSink(31810): Caused by: java.lang.NoSuchMethodException: <init> [class javax.crypto.CipherSpi, class java.lang.String]
/* This API isn't public - usually you're expected to simply use Cipher.getInstance().
* Due to the signed-jar restriction for JCE providers that is not an option, so we
* use one of the private constructors of Cipher.
*/
final Class<Cipher> cipherClass = Cipher.class;
final Constructor<Cipher> cipherConstructor = cipherClass.getDeclaredConstructor(CipherSpi.class, String.class);
cipherConstructor.setAccessible(true);
try {
return cipherConstructor.newInstance(cipherSpi, transformation);
}
catch (final InvocationTargetException e) {
throw e.getCause();
}
}
示例2: test_getBlockSize
import javax.crypto.CipherSpi; //導入依賴的package包/類
/**
* @tests javax.crypto.Cipher#getBlockSize()
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getBlockSize",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
clazz = CipherSpi.class,
method = "engineGetBlockSize",
args = {}
)
})
public void test_getBlockSize() throws Exception {
final String algorithm = "DESede/CBC/PKCS5Padding";
Cipher cipher = Cipher.getInstance(algorithm);
assertEquals("Block size does not match", 8, cipher.getBlockSize());
}
示例3: testGetParameters
import javax.crypto.CipherSpi; //導入依賴的package包/類
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getParameters",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
clazz = CipherSpi.class,
method = "engineGetParameters",
args = {}
)
})
public void testGetParameters() throws Exception {
Cipher c = Cipher.getInstance("DES");
assertNull(c.getParameters());
}
示例4: testGetIV
import javax.crypto.CipherSpi; //導入依賴的package包/類
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Checks inherited method from Cipher.",
method = "getIV",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Checks inherited method from Cipher.",
clazz = CipherSpi.class,
method = "engineGetIV",
args = {}
)
})
public void testGetIV() {
assertTrue("Incorrect IV", Arrays.equals(c.getIV(), new byte[8]));
}
示例5: cipherSpiSetPadding
import javax.crypto.CipherSpi; //導入依賴的package包/類
/**
* Sets the padding of a {@link javax.crypto.CipherSpi} instance.
*
* Like {@link #getCipher(String)}, we're accessing a private API
* here, so me must work around the access restrictions
*
* @param cipherSpi the {@link javax.crypto.CipherSpi} instance
* @param padding the padding to set
* @throws Throwable if {@link javax.crypto.CipherSpi#engineSetPadding} throws
*/
private static void cipherSpiSetPadding(final CipherSpi cipherSpi, final String padding) throws Throwable {
final Method engineSetPadding = getMethod(cipherSpi.getClass(), "engineSetPadding", String.class);
engineSetPadding.setAccessible(true);
try {
engineSetPadding.invoke(cipherSpi, padding);
}
catch (final InvocationTargetException e) {
throw e.getCause();
}
}
示例6: cipherSpiSetMode
import javax.crypto.CipherSpi; //導入依賴的package包/類
/**
* Sets the mode of a {@link javax.crypto.CipherSpi} instance.
*
* Like {@link #getCipher(String)}, we're accessing a private API
* here, so me must work around the access restrictions
*
* @param cipherSpi the {@link javax.crypto.CipherSpi} instance
* @param mode the mode to set
* @throws Throwable if {@link javax.crypto.CipherSpi#engineSetPadding} throws
*/
private static void cipherSpiSetMode(final CipherSpi cipherSpi, final String mode) throws Throwable {
final Method engineSetMode = getMethod(cipherSpi.getClass(), "engineSetMode", String.class);
engineSetMode.setAccessible(true);
try {
engineSetMode.invoke(cipherSpi, mode);
}
catch (final InvocationTargetException e) {
throw e.getCause();
}
}
示例7: test_getInstanceLjava_lang_String
import javax.crypto.CipherSpi; //導入依賴的package包/類
/**
* @tests javax.crypto.Cipher#getInstance(java.lang.String)
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getInstance",
args = {java.lang.String.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
clazz = CipherSpi.class,
method = "engineSetMode",
args = {java.lang.String.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
clazz = CipherSpi.class,
method = "engineSetPadding",
args = {java.lang.String.class}
)
})
public void test_getInstanceLjava_lang_String() throws Exception {
Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
assertNotNull("Received a null Cipher instance", cipher);
try {
Cipher.getInstance("WrongAlgorithmName");
fail("NoSuchAlgorithmException expected");
} catch (NoSuchAlgorithmException e) {
//expected
}
// RI throws NoSuchAlgorithmException for wrong padding.
}
示例8: test_getOutputSizeI
import javax.crypto.CipherSpi; //導入依賴的package包/類
/**
* @tests javax.crypto.Cipher#getOutputSize(int)
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getOutputSize",
args = {int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
clazz = CipherSpi.class,
method = "engineGetOutputSize",
args = {int.class}
)
})
public void test_getOutputSizeI() throws Exception {
SecureRandom sr = new SecureRandom();
Cipher cipher = Cipher.getInstance(algorithm + "/ECB/PKCS5Padding");
try {
cipher.getOutputSize(25);
fail("IllegalStateException expected");
} catch (IllegalStateException e) {
//expected
}
cipher.init(Cipher.ENCRYPT_MODE, cipherKey, sr);
// A 25-byte input could result in at least 4 8-byte blocks
int result = cipher.getOutputSize(25);
assertTrue("Output size too small", result > 31);
// A 8-byte input should result in 2 8-byte blocks
result = cipher.getOutputSize(8);
assertTrue("Output size too small", result > 15);
}
示例9: test_initILjava_security_KeyLjava_security_SecureRandom
import javax.crypto.CipherSpi; //導入依賴的package包/類
/**
* @tests javax.crypto.Cipher#init(int, java.security.Key,
* java.security.SecureRandom)
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "init",
args = {int.class, java.security.Key.class, java.security.SecureRandom.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
clazz = CipherSpi.class,
method = "engineInit",
args = {int.class, java.security.Key.class, java.security.SecureRandom.class}
)
})
public void test_initILjava_security_KeyLjava_security_SecureRandom()
throws Exception {
SecureRandom sr = new SecureRandom();
Cipher cipher = Cipher.getInstance(algorithm + "/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, cipherKey, sr);
cipher = Cipher.getInstance("DES/CBC/NoPadding");
try {
cipher.init(Cipher.ENCRYPT_MODE, cipherKey, sr);
fail("InvalidKeyException expected");
} catch (InvalidKeyException e) {
//expected
}
}
示例10: create
import javax.crypto.CipherSpi; //導入依賴的package包/類
public CipherSpi create(Object constructorParam) {
try {
return Adaptor.adapt(type.newInstance(), CipherSpi.class);
} catch (Exception e) {
throw new IllegalArgumentException("Invalid type: " + type, e);
}
}
示例11: testGetBlockSize001
import javax.crypto.CipherSpi; //導入依賴的package包/類
public final void testGetBlockSize001() throws Exception {
Provider.Service s = provider.getService("Cipher", algorithm);
PrivateProxy cipherSpi = PrivateProxyFactory.createPrivateProxy((CipherSpi) s.newInstance(null));
cipher = Cipher.getInstance(algorithm,provider);
cipher.init(Cipher.ENCRYPT_MODE, Util.getInstanceKey());
try {
assertEquals("Must be same blockSize",cipherSpi.call("engineGetBlockSize", new Object[0]),cipher.getBlockSize());
} catch (Throwable e) {
fail("fail with: " + e);
}
}
示例12: testCipher
import javax.crypto.CipherSpi; //導入依賴的package包/類
testCipher(CipherSpi c, Provider p, String s) {
super(c, p, s);
}
示例13: CipherSpiFactory
import javax.crypto.CipherSpi; //導入依賴的package包/類
public CipherSpiFactory(Class<? extends javax.crypto.CipherSpi> type) {
this.type = type;
}
示例14: CipherForKeyProtector
import javax.crypto.CipherSpi; //導入依賴的package包/類
/**
* Creates a Cipher object.
*
* @param cipherSpi the delegate
* @param provider the provider
* @param transformation the transformation
*/
protected CipherForKeyProtector(CipherSpi cipherSpi,
Provider provider,
String transformation) {
super(cipherSpi, provider, transformation);
}