0

我需要知道如何访问对象的值..例如在我的代码中

public static void main(String[] args) throws  Exception {
        Security.addProvider(new BouncyCastleProvider());
      BigInteger ZERO=new BigInteger("0");
       int c;
     ECCurve curve = new ECCurve.Fp(
            newBigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

ECParameterSpec ecSpec = new ECParameterSpec(
           curve,
            curve.decodePoint( Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
            new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n
KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECDSA", "BC");
kpg.initialize(ecSpec, new SecureRandom());
KeyPair keyPair = kpg.generateKeyPair();
PublicKey pubKey = keyPair.getPublic();
System.out.println(pubKey);
PrivateKey privKey = keyPair.getPrivate();
System.out.println(privKey);`

int y=numNoRange+p;//其中p是privatekey的值..这里还有我需要添加privatekey值的数字,但是private是对象,所以我需要知道如何从对象中检索值..谢谢..

4

2 回答 2

0

如果你知道 p 是什么类型的对象;然后就施放它。然后在这里获取值是从 double 转换为 int 的简单示例

double d = 3.5;
int x = (int) d;
于 2012-03-12T05:20:38.230 回答
0

PublicKey是用于表示非对称密码算法的公钥的基类。从本质上讲,它是一个结构,而不是一个单一的值。

例如,如果您使用 RSA 算法,那么您可以将您的公钥转换为 RSAPublicKey然后访问modulusand exponent

if (pubKey instanceof RSAPublicKey) {
    RSAPublicKey rsaPubKey = (RSAPublicKey)pubKey;
    BigInteger modulus = rsaPubKey.getModulus();
    BigInteger exponent = rsaPubKey.getPublicExponent();
    System.out.println("Modulus " + modulus.toString());
    System.out.println("Exponent " + exponent.toString());
}

对于椭圆曲线密码学,密钥由两个值组成 - 椭圆曲线的参数affineXaffineY

if (pubKey instanceof ECPublicKey) {
    ECPublicKey ecPubKey = (ECPublicKey)pubKey;
    ECPoint point = ecPubKey.getW();
    BigInteger affineX = point.getAffineX();
    BigInteger affineY = point.getAffineY();
    System.out.println("Affine X " + affineX.toString());
    System.out.println("Affine Y " + affineY.toString());
}

可以以相同的方式访问内部结构PrivateKey

于 2013-02-21T20:00:26.717 回答