EllipticCurves { public static byte[] ecdsaIeee2Der(byte[] ieee) throws GeneralSecurityException { if (ieee.length % 2 != 0 || ieee.length == 0 || ieee.length > 132) { throw new GeneralSecurityException("Invalid IEEE_P1363 encoding"); } byte[] r = toMinimalSignedNumber(Arrays.copyOf(ieee, ieee.length / 2)); byte[] s = toMinimalSignedNumber(Arrays.copyOfRange(ieee, ieee.length / 2, ieee.length)); int offset = 0; int length = 1 + 1 + r.length + 1 + 1 + s.length; byte[] der; if (length >= 128) { der = new byte[length + 3]; der[offset++] = (byte) 0x30; der[offset++] = (byte) (0x80 + 0x01); der[offset++] = (byte) length; } else { der = new byte[length + 2]; der[offset++] = (byte) 0x30; der[offset++] = (byte) length; } der[offset++] = (byte) 0x02; der[offset++] = (byte) r.length; System.arraycopy(r, 0, der, offset, r.length); offset += r.length; der[offset++] = (byte) 0x02; der[offset++] = (byte) s.length; System.arraycopy(s, 0, der, offset, s.length); return der; }  static ECParameterSpec getNistP256Params(); static ECParameterSpec getNistP384Params(); static ECParameterSpec getNistP521Params(); static boolean isNistEcParameterSpec(ECParameterSpec spec); static boolean isSameEcParameterSpec(ECParameterSpec one, ECParameterSpec two); static void validatePublicKey(ECPublicKey publicKey, ECPrivateKey privateKey); static BigInteger getModulus(EllipticCurve curve); static int fieldSizeInBytes(EllipticCurve curve); static BigInteger getY(BigInteger x, boolean lsb, EllipticCurve curve); static byte[] ecdsaIeee2Der(byte[] ieee); static byte[] ecdsaDer2Ieee(byte[] der, int ieeeLength); static boolean isValidDerEncoding(final byte[] sig); static int encodingSizeInBytes(EllipticCurve curve, PointFormatType format); @Deprecated static ECPoint ecPointDecode(EllipticCurve curve, PointFormatType format, byte[] encoded); static ECPoint pointDecode(CurveType curveType, PointFormatType format, byte[] encoded); static ECPoint pointDecode(EllipticCurve curve, PointFormatType format, byte[] encoded); static byte[] pointEncode(CurveType curveType, PointFormatType format, ECPoint point); static byte[] pointEncode(EllipticCurve curve, PointFormatType format, ECPoint point); static ECParameterSpec getCurveSpec(CurveType curve); static ECPublicKey getEcPublicKey(final byte[] x509PublicKey); static ECPublicKey getEcPublicKey(
      CurveType curve, PointFormatType pointFormat, final byte[] publicKey); static ECPublicKey getEcPublicKey(
      ECParameterSpec spec, PointFormatType pointFormat, final byte[] publicKey); static ECPublicKey getEcPublicKey(CurveType curve, final byte[] x, final byte[] y); static ECPrivateKey getEcPrivateKey(final byte[] pkcs8PrivateKey); static ECPrivateKey getEcPrivateKey(CurveType curve, final byte[] keyValue); static KeyPair generateKeyPair(CurveType curve); static KeyPair generateKeyPair(ECParameterSpec spec); static byte[] computeSharedSecret(ECPrivateKey myPrivateKey, ECPublicKey peerPublicKey); static byte[] computeSharedSecret(ECPrivateKey myPrivateKey, ECPoint publicPoint);  }
@Test public void testEcdsaIeee2Der() throws Exception { for (EcdsaIeeeDer test : ieeeDerTestVector) { assertArrayEquals( Hex.decode(test.hexDer), EllipticCurves.ecdsaIeee2Der(Hex.decode(test.hexIeee))); } }