| 501 | } |
| 502 | |
| 503 | private static BigInteger toPrivateKey(Object secret) { |
| 504 | Object v = (secret); |
| 505 | if (v instanceof BigInteger bi) return bi; |
| 506 | if (v instanceof byte[] b) return new BigInteger(1, b); |
| 507 | if (v instanceof String s) { |
| 508 | String t = s.trim(); |
| 509 | if (t.startsWith("0x")) return new BigInteger(t.substring(2), 16); |
| 510 | if (t.matches("^[0-9a-fA-F]+$")) return new BigInteger(t, 16); |
| 511 | if (t.matches("^[0-9]+$")) return new BigInteger(t, 10); |
| 512 | } |
| 513 | throw new IllegalArgumentException("Unsupported secret type: " + (v == null ? "null" : v.getClass().getName())); |
| 514 | } |
| 515 | |
| 516 | private static KeyPair ecKeyPairFromRaw(String curveStdName, byte[] privBytes) throws Exception { |
| 517 | // var params = ECNamedCurveTable.getParameterSpec(curveStdName); |