summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/uic/barcode/utils/AlgorithmNameResolver.java
blob: 44913585216756156e35377f95bab967c7d5b5b7 (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
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 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 prov) throws Exception {
	   
       	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;
	        	
	}    
    
  


}