/** * Returns a {@link SecretKey} formed from the hexadecimal key bytes (validity is checked). * * @param keyHex the key in hex form * @return the SecretKey */ public static SecretKey formKeyFromHex(String keyHex) throws KeyManagementException { if (keyIsValid(keyHex)) { return new SecretKeySpec(Hex.decode(keyHex), "AES"); } else { throw new KeyManagementException("The provided key material is not valid"); } }
private byte[] validateKey(String keyHex) { if (keyHex == null || StringUtils.isBlank(keyHex)) { throw new SensitivePropertyProtectionException("The key cannot be empty"); } keyHex = formatHexKey(keyHex); if (!isHexKeyValid(keyHex)) { throw new SensitivePropertyProtectionException("The key must be a valid hexadecimal key"); } byte[] key = Hex.decode(keyHex); final List<Integer> validKeyLengths = getValidKeyLengths(); if (!validKeyLengths.contains(key.length * 8)) { List<String> validKeyLengthsAsStrings = validKeyLengths.stream().map(i -> Integer.toString(i)).collect(Collectors.toList()); throw new SensitivePropertyProtectionException("The key (" + key.length * 8 + " bits) must be a valid length: " + StringUtils.join(validKeyLengthsAsStrings, ", ")); } return key; }
private static BigInteger fromHex( String hex) { return new BigInteger(1, Hex.decode(hex)); }
private static BigInteger fromHex( String hex) { return new BigInteger(1, Hex.decode(hex)); }
public SecP192R1Curve() { super(q); this.infinity = new SecP192R1Point(this, null, null); this.a = fromBigInteger(new BigInteger(1, Hex.decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC"))); this.b = fromBigInteger(new BigInteger(1, Hex.decode("64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1"))); this.order = new BigInteger(1, Hex.decode("FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831")); this.cofactor = BigInteger.valueOf(1); this.coord = SecP192R1_DEFAULT_COORDS; }
public SecP256R1Curve() { super(q); this.infinity = new SecP256R1Point(this, null, null); this.a = fromBigInteger(new BigInteger(1, Hex.decode("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC"))); this.b = fromBigInteger(new BigInteger(1, Hex.decode("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B"))); this.order = new BigInteger(1, Hex.decode("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551")); this.cofactor = BigInteger.valueOf(1); this.coord = SecP256R1_DEFAULT_COORDS; }
public SecP160R2Curve() { super(q); this.infinity = new SecP160R2Point(this, null, null); this.a = fromBigInteger(new BigInteger(1, Hex.decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC70"))); this.b = fromBigInteger(new BigInteger(1, Hex.decode("B4E134D3FB59EB8BAB57274904664D5AF50388BA"))); this.order = new BigInteger(1, Hex.decode("0100000000000000000000351EE786A818F3A1A16B")); this.cofactor = BigInteger.valueOf(1); this.coord = SecP160R2_DEFAULT_COORDS; }
private ASN1Primitive decodeObject(String oValue) { try { return ASN1Primitive.fromByteArray(Hex.decode(oValue.substring(1))); } catch (IOException e) { throw new IllegalStateException("unknown encoding in name: " + e); } }
public SecT571K1Curve() { super(571, 2, 5, 10); this.infinity = new SecT571K1Point(this, null, null); this.a = fromBigInteger(BigInteger.valueOf(0)); this.b = fromBigInteger(BigInteger.valueOf(1)); this.order = new BigInteger(1, Hex.decode("020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001")); this.cofactor = BigInteger.valueOf(4); this.coord = SecT571K1_DEFAULT_COORDS; }
public SecP160K1Curve() { super(q); this.infinity = new SecP160K1Point(this, null, null); this.a = fromBigInteger(ECConstants.ZERO); this.b = fromBigInteger(BigInteger.valueOf(7)); this.order = new BigInteger(1, Hex.decode("0100000000000000000001B8FA16DFAB9ACA16B6B3")); this.cofactor = BigInteger.valueOf(1); this.coord = SECP160K1_DEFAULT_COORDS; }
protected X9ECParameters createParameters() { byte[] S = Hex.decode("000E0D4D696E6768756151750CC03A4473D03679"); ECCurve curve = configureCurve(new SecP128R1Curve()); X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" + "161FF7528B899B2D0C28607CA52C5B86" + "CF5AC8395BAFEB13C02DA292DDED7A83")); return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); } };
protected X9ECParameters createParameters() { byte[] S = Hex.decode("3045AE6FC8422F64ED579528D38120EAE12196D5"); ECCurve curve = configureCurve(new SecP192R1Curve()); X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" + "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012" + "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811")); return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); } };
protected X9ECParameters createParameters() { byte[] S = Hex.decode("BD71344799D5C7FCDC45B59FA3B9AB8F6A948BC5"); ECCurve curve = configureCurve(new SecP224R1Curve()); X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" + "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21" + "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34")); return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); } };
protected X9ECParameters createParameters() { byte[] S = Hex.decode("1053CDE42C14D696E67687561517533BF3F83345"); ECCurve curve = configureCurve(new SecP160R1Curve()); X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" + "4A96B5688EF573284664698968C38BB913CBFC82" + "23A628553168947D59DCC912042351377AC5FB32")); return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); } };
protected X9ECParameters createParameters() { byte[] S = Hex.decode("B99B99B099B323E02709A4D696E6768756151751"); ECCurve curve = configureCurve(new SecP160R2Curve()); X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" + "52DCB034293A117E1F4FF11B30F7199D3144CE6D" + "FEAFFEF2E331F296E071FA0DF9982CFEA7D43F2E")); return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); } };
protected X9ECParameters createParameters() { byte[] S = Hex.decode("103FAEC74D696E676875615175777FC5B191EF30"); ECCurve curve = configureCurve(new SecT193R1Curve()); X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" + "01F481BC5F0FF84A74AD6CDF6FDEF4BF6179625372D8C0C5E1" + "0025E399F2903712CCF3EA9E3A1AD17FB0B3201B6AF7CE1B05")); return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); } };
protected X9ECParameters createParameters() { byte[] S = Hex.decode("2AA058F73A0E33AB486B0F610410C53A7F132310"); ECCurve curve = configureCurve(new SecT571R1Curve()); X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" + "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19" + "037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B")); return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); } };
protected X9ECParameters createParameters() { byte[] S = null; ECCurve curve = configureCurve(new SecT233K1Curve()); X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" + "017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126" + "01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3")); return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); } };
@Test public void parseGenesisBlockWithZeroProposerSeal() { final byte[] genesisBlockExtraData = Hex.decode( "0000000000000000000000000000000000000000000000000000000000000000f89af85494c332d0db1704d18f89a590e7586811e36d37ce049424defc2d149861d3d245749b81fe0e6b28e04f31943814f17bd4b7ce47ab8146684b3443c0a4b2fc2c942a813d7db3de19b07f92268b6d4125ed295cbe00b8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0"); final BytesValue bufferToInject = BytesValue.wrap(genesisBlockExtraData); final IbftExtraData extraData = IbftExtraData.decode(bufferToInject); assertThat(extraData.getProposerSeal()).isNull(); } }