2012-03-12 40 views
0

我需要知道如何访问object..for示例的值在我的代码 '如何从对象的Java

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Ŷ检索值= numNoRange + P; //其中p是我需要添加专用密钥值数一起privatekey..here的价值,但私人的对象,所以我需要知道如何从object..Thank您检索值..

+0

您正在试图了解(这是专用密钥类的对象)中privJKey价值? – 2012-03-12 05:03:12

回答

0

,如果你知道什么样的对象p是;然后只是施放它。那么获得的价值 这里是双铸造为int

double d = 3.5; 
int x = (int) d; 
0

PublicKey为代表的非对称加密算法的公钥基类的简单例子。它的本质就是一个结构,而不是一个单一的价值。例如,如果您使用RSA算法,则可以将您的公钥转换为 RSAPublicKey,然后访问modulusexponent

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()); 
} 

对于椭圆曲线加密密钥由两个值 - 的椭圆曲线affineX的参数和affineY

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相同方式的内部结构可被访问。