2012-03-12 27 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相同方式的內部結構可被訪問。