本文整理汇总了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
}
示例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
}