Java 类javax.crypto.CipherSpi 实例源码

项目:Android-Airplay-Server    文件:AirTunesCryptography.java   
/**
 * 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();
    }
}
项目:AirSpeakerMobile    文件:AirTunesCryptography.java   
/**
 * 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();
    }
}
项目:In-the-Box-Fork    文件:CipherTest.java   
/**
 * @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());
}
项目:In-the-Box-Fork    文件:CipherTest.java   
@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());
}
项目:In-the-Box-Fork    文件:NullCipherTest.java   
@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]));
}
项目:Android-Airplay-Server    文件:AirTunesCryptography.java   
/**
 * 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();
    }
}
项目:Android-Airplay-Server    文件:AirTunesCryptography.java   
/**
 * 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();
    }
}
项目:AirSpeakerMobile    文件:AirTunesCryptography.java   
/**
 * 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();
    }
}
项目:AirSpeakerMobile    文件:AirTunesCryptography.java   
/**
 * 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();
    }
}
项目:In-the-Box-Fork    文件:CipherTest.java   
/**
     * @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.
    }
项目:In-the-Box-Fork    文件:CipherTest.java   
/**
 * @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);
}
项目:In-the-Box-Fork    文件:CipherTest.java   
/**
 * @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
    }
}
项目:crypto-gwt    文件:CipherSpiFactory.java   
public CipherSpi create(Object constructorParam) {
    try {
        return Adaptor.adapt(type.newInstance(), CipherSpi.class);
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid type: " + type, e);
    }
}
项目:freeVM    文件:TestCipherStatic.java   
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);
    }
}
项目:In-the-Box-Fork    文件:CipherTest.java   
testCipher(CipherSpi c, Provider p, String s) {
    super(c, p, s);
}
项目:crypto-gwt    文件:CipherSpiFactory.java   
public CipherSpiFactory(Class<? extends javax.crypto.CipherSpi> type) {
    this.type = type;
}
项目:cn1    文件:CipherTest.java   
testCipher(CipherSpi c, Provider p, String s) {
    super(c, p, s);
}
项目:freeVM    文件:CipherTest.java   
testCipher(CipherSpi c, Provider p, String s) {
    super(c, p, s);
}
项目:freeVM    文件:CipherTest.java   
testCipher(CipherSpi c, Provider p, String s) {
    super(c, p, s);
}
项目:OpenJSharp    文件:KeyProtector.java   
/**
 * 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);
}
项目:jdk8u-jdk    文件:KeyProtector.java   
/**
 * 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);
}
项目:openjdk-jdk10    文件:KeyProtector.java   
/**
 * 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);
}
项目:openjdk9    文件:KeyProtector.java   
/**
 * 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);
}
项目:jdk8u_jdk    文件:KeyProtector.java   
/**
 * 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);
}
项目:lookaside_java-1.8.0-openjdk    文件:KeyProtector.java   
/**
 * 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);
}
项目:infobip-open-jdk-8    文件:KeyProtector.java   
/**
 * 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);
}
项目:jdk8u-dev-jdk    文件:KeyProtector.java   
/**
 * 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);
}
项目:jdk7-jdk    文件:KeyProtector.java   
/**
 * 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);
}
项目:openjdk-source-code-learn    文件:KeyProtector.java   
/**
 * 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);
}
项目:OLD-OpenJDK8    文件:KeyProtector.java   
/**
 * 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);
}
项目:openjdk-jdk7u-jdk    文件:KeyProtector.java   
/**
 * 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);
}
项目:openjdk-icedtea7    文件:KeyProtector.java   
/**
 * 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);
}