Java ECC Programming Example (1)


  / ** 
  * @ Author zflunu 
*
  * / 

  / / This is an example for ECC usage 

  / / The following are the Interfaces 
  Import java.security.spec.ECField; 
  Import java.security.interfaces.ECKey; 
  Import java.security.interfaces.ECPublicKey; 
  Import java.security.interfaces.ECPrivateKey; 


  / / The following are the Classes 
  Import java.security.spec.ECFieldF2m; 
  Import java.security.spec.ECFieldFp; 
  Import java.security.spec.EllipticCurve; 
  Import java.security.spec.ECGenParameterSpec; 
  Import java.security.spec.ECParameterSpec; 
  Import java.security.spec.ECPoint; 
  Import java.security.spec.ECPrivateKeySpec; 
  Import java.security.spec.ECPublicKeySpec; 


  Import java.math.BigInteger; 


  (Public class ECCex1 

  / ** 
  * @ Param args 
  * / 
  Public static void main (String [] args) ( 

  System.out.println ( "This is the ECC example"); 

  System.out.println ( "The following is about the ECFieldF2m"); 
  / / 163 + x ^ x ^ 7 + 6 + x ^ x ^ 3 +1 
  Int m = 163; 
  Ks int [] = (7,6,3); 
  ECFieldF2m myECFieldF2m = new ECFieldF2m (m, ks); 
  System.out.println ( "Field size is:" + myECFieldF2m.getFieldSize ()); 
  System.out.println ( "The m value is:" + myECFieldF2m.getM ()); 
  Int [] = mid myECFieldF2m.getMidTermsOfReductionPolynomial (); 
  System.out.println ( "the mid terms are:" + mid [0] + "" + mid [1] + "" + mid [2]); 
  System.out.println ( "The ReductionPolynomial is:" + myECFieldF2m.getReductionPolynomial (). ToString (16)); 




  System.out.println ( "The following is about the EllipticCurve"); 
  / / Y ^ 2 + xy = x ^ 3 + x ^ 2 +1 
  BigInteger a = new BigInteger ( "1", 2); / / BigInteger (String val, int radix) 
  BigInteger b = new BigInteger ( "1", 2); 
  / / Seed byte [] = (15, 16, 17); 

  EllipticCurve myEllipticCurve = new EllipticCurve (myECFieldF2m, a, b); 


  System.out.println ( "The coefficient a is:" + myEllipticCurve.getA (). ToString (2)); 
  System.out.println ( "The coefficient b is:" + myEllipticCurve.getB (). ToString (2)); 
  ECFieldF2m myfield = (ECFieldF2m) myEllipticCurve.getField (); 
  System.out.println ( "The ReductionPolynomial of the field is:" + myfield.getReductionPolynomial (). ToString (16)); 
  / / Byte [] = myseed myEllipticCurve.getSeed (); 
  / / System.out.println ( "the seed is are:" + myseed [0] + "" + myseed [1] + "" + myseed [2]); 




  ECPoint g = new ECPoint (new BigInteger ( "2fe13c0537bbc11acaa07d793de4e6d5e5c94eee8", 16), 
  New BigInteger ( "289070fb05d38ff58321f2e800536d538ccdaa3d9", 16)); 
  / / The order of generator 
  BigInteger n = new BigInteger ( "5846006549323611672814741753598448348329118574063", 10); 
  / / The cofactor 
  Int h = 2; 

  / / ECParameterSpec (EllipticCurve curve, ECPoint g, BigInteger n, int h) 
  ECParameterSpec myECParameterSpec = new ECParameterSpec (myEllipticCurve, g, n, h); 
  System.out.println ( "The order is:" + myECParameterSpec.getOrder (). ToString ()); 

  BigInteger s = new BigInteger ( "1234006549323611672814741753598448348329118574063", 10); 
  ECPrivateKeySpec myECPrivateKeySpec = new ECPrivateKeySpec (s, myECParameterSpec); 
  System.out.println ( "The private key is:" + myECPrivateKeySpec.getS (). ToString ()); 

  / / ECPoint w = sg; 

  / / ECPublicKeySpec myECPublicKeySpec = new ECPublicKeySpec (w, myECParameterSpec) 



  ) 

  ) 


Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: ,

Releated Java Articles

Comments

Leave a Reply