要求:对于给定的命名曲线,尽可能少地发送数据,以便接收者可以构建EC PrivateKey。
我目前在Android上使用BouncyCastle / SpongyCastle。这是我迄今所理解的。
$imageName = $_FILES['userfile']['name'];
$str=strpos($imageName,'.');
$ext=substr($imageName,$str+1,strlen($imageName)-$str-1);
if($ext=='png')
{
if(move_uploaded_file($image[$i], $path.$imageName[$i])) {
$result = $mysqli->query("INSERT INTO imageTable (imageName, imageCategory, imageSize, imageType) VALUES ('$imageName[$i]', '$imageCategory', '$imageSize[$i]' , '$imageType[$i]' )");
$melding = "Item is succesvol geupload!";
}
}
现在,使用Bouncy / Spongy城堡,我得到私钥的实际点,而没有任何其他信息存在于derEncoding中。
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC");
ECGenParameterSpec ecGenParameterSpec = new ECGenParameterSpec("secp112r2");
keyGen.initialize(ecGenParameterSpec, new SecureRandom());
KeyPair keyPair = keyGen.generateKeyPair();
PrivateKey privateKey = keyPair.getPrivate();
// privateKey.getEncoded() -> gives DER encoded private key. I can construct PrivateKey from that easily
byte[] derEncodedPrivateKeyBytes = privateKey.getEncoded(); // byteArray length-> 80
KeyFactory kf = KeyFactory.getInstance("EC");
PrivateKey key = kf.generatePrivate(new PKCS8EncodedKeySpec(derEncodedPrivateKeyBytes));
问题:如何使用点 D (ECPrivateKeyParameters param = (ECPrivateKeyParameters) ECUtil.generatePrivateKeyParameter(privateKey);
int lenghtOfKey = param.getD().toByteArray().length; // length - 14
)和曲线名称重建PrivateKey对象?使用曲线名称,我可以获得ECCurveParameters。
修改:我可以使用私钥点(privateKeyParam.getD()
)构建ECPrivateKeyParameters
,但仍无法弄清楚如何从praram.getD()
生成私钥。
ECPrivateKeyParameters
答案 0 :(得分:4)
我能够弄清楚如何从BigInteger D& D中重新构建EC PrivateKey。曲线名称。
public static PrivateKey getPrivateKeyFromECBigIntAndCurve(BigInteger s, String curveName) {
X9ECParameters ecCurve = ECNamedCurveTable.getByName(curveName);
ECParameterSpec ecParameterSpec = new ECNamedCurveSpec(curveName, ecCurve.getCurve(), ecCurve.getG(), ecCurve.getN(), ecCurve.getH(), ecCurve.getSeed());
ECPrivateKeySpec privateKeySpec = new ECPrivateKeySpec(s, ecParameterSpec);
try {
KeyFactory keyFactory = KeyFactory.getInstance("EC");
return keyFactory.generatePrivate(privateKeySpec);
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
e.printStackTrace();
return null;
}
}