MCPcopy Create free account
hub / github.com/DeNA/PacketProxy / sign

Method sign

src/main/java/core/org/xbill/DNS/DNSSEC.java:938–991  ·  view source on GitHub ↗
(PrivateKey privkey, PublicKey pubkey, int alg, byte [] data,
     String provider)

Source from the content-addressed store, hash-verified

936}
937
938private static byte []
939sign(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}
992static void
993checkAlgorithm(PrivateKey key, int alg) throws UnsupportedAlgorithmException
994{

Callers 2

signMessageMethod · 0.95
createSignatureMethod · 0.80

Calls 15

algStringMethod · 0.95
BigIntegerLengthMethod · 0.95
DSASignaturetoDNSMethod · 0.95
ECDSASignaturetoDNSMethod · 0.95
checkAlgorithmMethod · 0.95
digestRRsetMethod · 0.95
setSignatureMethod · 0.80
getPublicKeyMethod · 0.80
getNameMethod · 0.65
getTypeMethod · 0.65
getInstanceMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected