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


Java SecretKey.getClass方法代码示例

本文整理汇总了Java中javax.crypto.SecretKey.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java SecretKey.getClass方法的具体用法?Java SecretKey.getClass怎么用?Java SecretKey.getClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.crypto.SecretKey的用法示例。


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

示例1: testCleanupSecret

import javax.crypto.SecretKey; //导入方法依赖的package包/类
static void testCleanupSecret(String algorithm) throws Exception {
    KeyGenerator desGen = KeyGenerator.getInstance(algorithm, SunJCEProvider);
    SecretKey key = desGen.generateKey();

    // Break into the implementation to observe the key byte array.
    Class<?> keyClass = key.getClass();
    Field keyField = keyClass.getDeclaredField("key");
    keyField.setAccessible(true);
    byte[] array = (byte[])keyField.get(key);

    byte[] zeros = new byte[array.length];
    do {
        // Wait for array to be cleared;  if not cleared test will timeout
        System.out.printf("%s array: %s%n", algorithm, Arrays.toString(array));
        key = null;
        System.gc();        // attempt to reclaim the key
    } while (Arrays.compare(zeros, array) != 0);
    System.out.printf("%s array: %s%n", algorithm, Arrays.toString(array));

    Reference.reachabilityFence(key); // Keep key alive
    Reference.reachabilityFence(array); // Keep array alive
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:DESKeyCleanupTest.java

示例2: testCleanupSecret

import javax.crypto.SecretKey; //导入方法依赖的package包/类
static void testCleanupSecret(String algorithm, SecretKey key) throws Exception {

        // Break into the implementation to observe the key byte array.
        Class<?> keyClass = key.getClass();
        Field keyField = keyClass.getDeclaredField("key");
        keyField.setAccessible(true);
        byte[] array = (byte[])keyField.get(key);

        byte[] zeros = new byte[array.length];
        do {
            // Wait for array to be cleared;  if not cleared test will timeout
            System.out.printf("%s array: %s%n", algorithm, Arrays.toString(array));
            key = null;
            System.gc();        // attempt to reclaim the key
        } while (Arrays.compare(zeros, array) != 0);
        System.out.printf("%s array: %s%n", algorithm, Arrays.toString(array));

        Reference.reachabilityFence(key); // Keep key alive
        Reference.reachabilityFence(array); // Keep array alive
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:PBEKeyCleanupTest.java


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