blob: a3154f3f2a447d1808b9951834e20f7c22539cc0 (
plain) (
blame)
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
90
91
92
93
94
95
96
97
98
99
100
101
|
package org.uic.barcode.utils;
import java.security.Provider;
import java.security.Provider.Service;
import java.security.Security;
public class AlgorithmNameResolver {
public static final String TYPE_KEY_GENERATOR_ALG = "KeyPairGenerator";
public static final String TYPE_SIGNATURE_ALG = "Signature";
public static String getSignatureAlgorithmName (String oid) throws Exception {
Provider[] provs = Security.getProviders();
for (Provider prov : provs) {
Service service = prov.getService(AlgorithmNameResolver.TYPE_SIGNATURE_ALG,oid);
if (service != null) {
return service.getAlgorithm();
}
}
return null;
}
public static String getSignatureAlgorithmName (String oid, Provider provider) throws Exception {
if (provider != null) {
Service service = provider.getService(AlgorithmNameResolver.TYPE_SIGNATURE_ALG,oid);
return service.getAlgorithm();
}
Provider[] provs = Security.getProviders();
for (Provider prov : provs) {
Service service = prov.getService(AlgorithmNameResolver.TYPE_SIGNATURE_ALG,oid);
if (service != null) {
return service.getAlgorithm();
}
}
return null;
}
public static String getName (String type, String oid) throws Exception {
Provider[] provs = Security.getProviders();
for (Provider prov : provs) {
Service service = prov.getService(type,oid);
if (service != null) {
return service.getAlgorithm();
}
}
if (oid.startsWith("1.2.840.10045")) {
return "ECDSA";
} else if (oid.startsWith("1.2.840.10040")) {
return "DSA";
}
return null;
}
public static String getName(String type, String oid, Provider provider) throws Exception {
Service service = null;
if (provider == null) {
Provider[] provs = Security.getProviders();
for (Provider prov : provs) {
service = prov.getService(type,oid);
}
} else {
service = provider.getService(type,oid);
}
if (service != null) {
return service.getAlgorithm();
}
if (oid.startsWith("1.2.840.10045")) {
return "ECDSA";
} else if (oid.startsWith("1.2.840.10040")) {
return "DSA";
}
return null;
}
}
|