(PrivateKey privkey, PublicKey pubkey, int alg, byte [] data,
String provider)
| 936 | } |
| 937 | |
| 938 | private static byte [] |
| 939 | sign(PrivateKey privkey, PublicKey pubkey, int alg, byte [] data, |
| 940 | String provider) throws DNSSECException |
| 941 | { |
| 942 | byte [] signature; |
| 943 | try { |
| 944 | Signature s; |
| 945 | if (provider != null) |
| 946 | s = Signature.getInstance(algString(alg), provider); |
| 947 | else |
| 948 | s = Signature.getInstance(algString(alg)); |
| 949 | s.initSign(privkey); |
| 950 | s.update(data); |
| 951 | signature = s.sign(); |
| 952 | } |
| 953 | catch (GeneralSecurityException e) { |
| 954 | throw new DNSSECException(e.toString()); |
| 955 | } |
| 956 | |
| 957 | if (pubkey instanceof DSAPublicKey) { |
| 958 | try { |
| 959 | DSAPublicKey dsa = (DSAPublicKey) pubkey; |
| 960 | BigInteger P = dsa.getParams().getP(); |
| 961 | int t = (BigIntegerLength(P) - 64) / 8; |
| 962 | signature = DSASignaturetoDNS(signature, t); |
| 963 | } |
| 964 | catch (IOException e) { |
| 965 | throw new IllegalStateException(); |
| 966 | } |
| 967 | } else if (pubkey instanceof ECPublicKey) { |
| 968 | try { |
| 969 | switch (alg) { |
| 970 | case Algorithm.ECC_GOST: |
| 971 | // Wire format is equal to the engine output |
| 972 | break; |
| 973 | case Algorithm.ECDSAP256SHA256: |
| 974 | signature = ECDSASignaturetoDNS(signature, |
| 975 | ECDSA_P256); |
| 976 | break; |
| 977 | case Algorithm.ECDSAP384SHA384: |
| 978 | signature = ECDSASignaturetoDNS(signature, |
| 979 | ECDSA_P384); |
| 980 | break; |
| 981 | default: |
| 982 | throw new UnsupportedAlgorithmException(alg); |
| 983 | } |
| 984 | } |
| 985 | catch (IOException e) { |
| 986 | throw new IllegalStateException(); |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | return signature; |
| 991 | } |
| 992 | static void |
| 993 | checkAlgorithm(PrivateKey key, int alg) throws UnsupportedAlgorithmException |
| 994 | { |
no test coverage detected