aboutsummaryrefslogtreecommitdiffstats
path: root/libraries/spongycastle/core/src/main/jdk1.1/java/security/KeyFactory.java
blob: 320aac3f8c45ecf859941224b28f967011f561df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package java.security;

import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;

public class KeyFactory extends Object
{
    private KeyFactorySpi keyFacSpi;
    private Provider provider;
    private String algorithm;

    protected KeyFactory(
        KeyFactorySpi keyFacSpi,
        Provider provider,
        String algorithm)
    {
        this.keyFacSpi = keyFacSpi;
        this.provider = provider;
        this.algorithm = algorithm;
    }

    public final PrivateKey generatePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
    {
        return keyFacSpi.engineGeneratePrivate(keySpec);
    }

    public final PublicKey generatePublic(KeySpec keySpec)
    throws InvalidKeySpecException
    {
        return keyFacSpi.engineGeneratePublic(keySpec);
    }

    public final String getAlgorithm()
    {
        return algorithm;
    }

    public static KeyFactory getInstance(String algorithm)
    throws NoSuchAlgorithmException
    {
        try
        {
            SecurityUtil.Implementation  imp = SecurityUtil.getImplementation("KeyFactory", algorithm, null);

            if (imp != null)
            {
                return new KeyFactory((KeyFactorySpi)imp.getEngine(), imp.getProvider(), algorithm);
            }

            throw new NoSuchAlgorithmException("can't find algorithm " + algorithm);
        }
        catch (NoSuchProviderException e)
        {
            throw new NoSuchAlgorithmException(algorithm + " not found");
        }
    }

    public static KeyFactory getInstance(String algorithm, String provider)
    throws NoSuchAlgorithmException, NoSuchProviderException
    {
        SecurityUtil.Implementation  imp = SecurityUtil.getImplementation("KeyFactory", algorithm, null);

        if (imp != null)
        {
            return new KeyFactory((KeyFactorySpi)imp.getEngine(), imp.getProvider(), algorithm);
        }

        throw new NoSuchAlgorithmException("can't find algorithm " + algorithm);
    }

    public final KeySpec getKeySpec(Key key, Class keySpec)
    throws InvalidKeySpecException
    {
        return keyFacSpi.engineGetKeySpec(key, keySpec);
    }

    public final Provider getProvider()
    {
        return provider;
    }

    public final Key translateKey(Key key)
    throws InvalidKeyException
    {
        return keyFacSpi.engineTranslateKey(key);
    }
}