Skip to content

Commit bba445e

Browse files
committed
Add PrivateKeyUtil class
1 parent bd28358 commit bba445e

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.bouncycastle.tls.crypto.impl.jcajce;
2+
3+
import java.lang.reflect.Method;
4+
import java.security.PrivateKey;
5+
6+
import org.bouncycastle.tls.ReflectionUtil;
7+
8+
abstract class PrivateKeyUtil
9+
{
10+
private static final Method destroy;
11+
12+
static
13+
{
14+
Method[] methods = ReflectionUtil.getMethods("java.security.PrivateKey");
15+
16+
destroy = ReflectionUtil.findMethod(methods, "destroy");
17+
}
18+
19+
static void destroy(PrivateKey privateKey)
20+
{
21+
if (destroy != null)
22+
{
23+
try
24+
{
25+
ReflectionUtil.invokeMethod(privateKey, destroy);
26+
}
27+
catch (Exception e)
28+
{
29+
}
30+
}
31+
}
32+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.bouncycastle.tls.crypto.impl.jcajce;
2+
3+
import java.security.PrivateKey;
4+
5+
abstract class PrivateKeyUtil
6+
{
7+
void destroy(PrivateKey privateKey)
8+
{
9+
try
10+
{
11+
privateKey.destroy();
12+
}
13+
catch (Exception e)
14+
{
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)