当前位置: 首页>>代码示例>>Java>>正文


Java SecretKeyFactorySpi类代码示例

本文整理汇总了Java中javax.crypto.SecretKeyFactorySpi的典型用法代码示例。如果您正苦于以下问题:Java SecretKeyFactorySpi类的具体用法?Java SecretKeyFactorySpi怎么用?Java SecretKeyFactorySpi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SecretKeyFactorySpi类属于javax.crypto包,在下文中一共展示了SecretKeyFactorySpi类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSecretKeyFactory01

import javax.crypto.SecretKeyFactorySpi; //导入依赖的package包/类
/**
 * Test for <code>SecretKeyFactory</code> constructor
 * Assertion: returns SecretKeyFactory object
 */
public void testSecretKeyFactory01() throws NoSuchAlgorithmException,
        InvalidKeySpecException, InvalidKeyException {
    if (!DEFSupported) {
        fail(NotSupportMsg);
        return;
    }
    SecretKeyFactorySpi spi = new MySecretKeyFactorySpi();
    SecretKeyFactory secKF = new mySecretKeyFactory(spi, defaultProvider,
            defaultAlgorithm);
    assertEquals("Incorrect algorithm", secKF.getAlgorithm(),
            defaultAlgorithm);
    assertEquals("Incorrect provider", secKF.getProvider(), defaultProvider);
    assertNull("Incorrect result", secKF.generateSecret(null));
    assertNull("Incorrect result", secKF.getKeySpec(null, null));
    assertNull("Incorrect result", secKF.translateKey(null));
    secKF = new mySecretKeyFactory(null, null, null);
    assertNull("Algorithm must be null", secKF.getAlgorithm());
    assertNull("Provider must be null", secKF.getProvider());
    try {
        secKF.translateKey(null);
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {            
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:29,代码来源:SecretKeyFactoryTest.java

示例2: testSecretKeyFactory01

import javax.crypto.SecretKeyFactorySpi; //导入依赖的package包/类
/**
 * Test for <code>SecretKeyFactory</code> constructor
 * Assertion: returns SecretKeyFactory object
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "SecretKeyFactory",
    args = {javax.crypto.SecretKeyFactorySpi.class, java.security.Provider.class, java.lang.String.class}
)
public void testSecretKeyFactory01() throws NoSuchAlgorithmException,
        InvalidKeySpecException, InvalidKeyException {
    if (!DEFSupported) {
        fail(NotSupportMsg);
        return;
    }
    SecretKeyFactorySpi spi = new MySecretKeyFactorySpi();
    SecretKeyFactory secKF = new mySecretKeyFactory(spi, defaultProvider,
            defaultAlgorithm);
    assertEquals("Incorrect algorithm", secKF.getAlgorithm(),
            defaultAlgorithm);
    assertEquals("Incorrect provider", secKF.getProvider(), defaultProvider);
    assertNull("Incorrect result", secKF.generateSecret(null));
    assertNull("Incorrect result", secKF.getKeySpec(null, null));
    assertNull("Incorrect result", secKF.translateKey(null));
    secKF = new mySecretKeyFactory(null, null, null);
    assertNull("Algorithm must be null", secKF.getAlgorithm());
    assertNull("Provider must be null", secKF.getProvider());
    try {
        secKF.translateKey(null);
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:35,代码来源:SecretKeyFactoryTest.java

示例3: test_translateKeyLjavax_crypto_SecretKey

import javax.crypto.SecretKeyFactorySpi; //导入依赖的package包/类
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        method = "translateKey",
        args = {javax.crypto.SecretKey.class}
    ),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        clazz = SecretKeyFactorySpi.class,
        method = "engineTranslateKey",
        args = {javax.crypto.SecretKey.class}
    )
})
public void test_translateKeyLjavax_crypto_SecretKey()
        throws NoSuchAlgorithmException, InvalidKeyException {
    KeyGenerator kg = null;
    Key key = null;
    SecretKeyFactory secKF = null;

    for (int i = 0; i < validValues.length; i++) {
        secKF = SecretKeyFactory
                .getInstance(validValues[i]);
        assertNotNull(secKF.getProvider());
        kg = KeyGenerator.getInstance(secKF.getAlgorithm());
        kg.init(new SecureRandom());
        key = kg.generateKey();

        secKF.translateKey((SecretKey) key);
    }
    try {
        secKF.translateKey(null);
        fail("InvalidKeyException expected");
    } catch (InvalidKeyException e) {
        //expected
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:39,代码来源:SecretKeyFactoryTest.java

示例4: AsyncSecretKeyFactory

import javax.crypto.SecretKeyFactorySpi; //导入依赖的package包/类
protected AsyncSecretKeyFactory(final SecretKeyFactorySpi keyFacSpi,
        Provider provider, String algorithm) {
    super(keyFacSpi, provider, algorithm);
    if (keyFacSpi instanceof AsyncSecretKeyFactorySpi) {
        asyncSpi = (AsyncSecretKeyFactorySpi) keyFacSpi;
        return;
    }                 
}
 
开发者ID:ivanceras,项目名称:crypto-gwt,代码行数:9,代码来源:AsyncSecretKeyFactory.java

示例5: getAsyncInstance

import javax.crypto.SecretKeyFactorySpi; //导入依赖的package包/类
public static final AsyncSecretKeyFactory getAsyncInstance(String algorithm,
        Provider provider) throws NoSuchAlgorithmException {
    if (provider == null) throw new IllegalArgumentException();
    Provider.Service service = provider.getService("SecretKeyFactory", algorithm);
    if (service != null) {
        return new AsyncSecretKeyFactory(
                (SecretKeyFactorySpi) service.newInstance(null), 
                provider, 
                algorithm);
    }        
    throw new NoSuchAlgorithmException("Invalid secret key factory: " + algorithm);
}
 
开发者ID:ivanceras,项目名称:crypto-gwt,代码行数:13,代码来源:AsyncSecretKeyFactory.java

示例6: create

import javax.crypto.SecretKeyFactorySpi; //导入依赖的package包/类
public SecretKeyFactorySpi create(Object constructorParam) {
    try {
        return Adaptor.adapt(type.newInstance(), SecretKeyFactorySpi.class);
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid type: " + type, e);
    }
}
 
开发者ID:ivanceras,项目名称:crypto-gwt,代码行数:8,代码来源:SecretKeyFactorySpiFactory.java

示例7: getSecretKeyFactory

import javax.crypto.SecretKeyFactorySpi; //导入依赖的package包/类
/**
 * Factory method to get the proper factory class. The SunJCE provider
 * appears to have its own classloader so simply adding the values (as
 * above) does not work and the classes are not found. Hence the reflection
 * work below.
 *
 * @param algorithm
 * @return
 * @throws NoSuchAlgorithmException
 */
@SuppressWarnings("unchecked")
public static SecretKeyFactory getSecretKeyFactory(String algorithm) throws NoSuchAlgorithmException {
    try {
        Class<SecretKeyFactorySpi> clazz = (Class<SecretKeyFactorySpi>) Class.forName((String) provider.get("SecretKeyFactory." + algorithm));
        SecretKeyFactorySpi spi = clazz.newInstance();
        Constructor<SecretKeyFactory> c = SecretKeyFactory.class.getDeclaredConstructor(SecretKeyFactorySpi.class, Provider.class, String.class);
        c.setAccessible(true);
        return c.newInstance(spi, provider, algorithm);
    } catch (Exception e) {
        throw new NoSuchAlgorithmException(e);
    }
}
 
开发者ID:Glamdring,项目名称:saltedhashed,代码行数:23,代码来源:PBKDF2Algorithms.java

示例8: SecretKeyFactory

import javax.crypto.SecretKeyFactorySpi; //导入依赖的package包/类
/** @ar.org.fitc.spec_ref */
protected SecretKeyFactory(SecretKeyFactorySpi keyFacSpi,
        Provider provider, String algorithm) {
    this.secretKeyFactorySpi = keyFacSpi;
    this.provider = provider;
    this.algorithm = algorithm;
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:8,代码来源:SecretKeyFactory.java

示例9: Mock_SecretKeyFactory

import javax.crypto.SecretKeyFactorySpi; //导入依赖的package包/类
protected Mock_SecretKeyFactory(SecretKeyFactorySpi arg0, Provider arg1, String arg2) {
    super(arg0, arg1, arg2);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:4,代码来源:SecretKeyFactoryTest.java

示例10: mySecretKeyFactory

import javax.crypto.SecretKeyFactorySpi; //导入依赖的package包/类
public mySecretKeyFactory(SecretKeyFactorySpi spi, Provider prov, String alg) {
    super(spi, prov, alg);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:4,代码来源:SecretKeyFactoryTest.java

示例11: SecretKeyFactorySpiFactory

import javax.crypto.SecretKeyFactorySpi; //导入依赖的package包/类
public SecretKeyFactorySpiFactory(Class<? extends javax.crypto.SecretKeyFactorySpi> type) {
    this.type = type;
}
 
开发者ID:ivanceras,项目名称:crypto-gwt,代码行数:4,代码来源:SecretKeyFactorySpiFactory.java

示例12: newInstance

import javax.crypto.SecretKeyFactorySpi; //导入依赖的package包/类
/**
 * It's used as a factory method
 * 
 * @param algorithm
 *            the algorithm
 * @param provider
 *            the provider
 * @return a new SecretKeyFactory object
 * @throws NoSuchAlgorithmException
 *             if the specified algorithm is not available in the default
 *             package or any of the others providers that were searched
 */
private static final SecretKeyFactory newInstance(String algorithm,
        Provider provider) throws NoSuchAlgorithmException {
    Service service = Util.getService(Types.SECRET_KEY_FACTORY, algorithm,
            provider);
    if (service == null) {
        throw new NoSuchAlgorithmException("No such algorithm: "
                + algorithm);
    }
    return new SecretKeyFactory((SecretKeyFactorySpi) service
            .newInstance(null), service.getProvider(), algorithm);
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:24,代码来源:SecretKeyFactory.java


注:本文中的javax.crypto.SecretKeyFactorySpi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。