RSA??????? - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

RSA???????

Description:

Title: PowerPoint Presentation Last modified by: tiyzhao Created Date: 1/1/1601 12:00:00 AM Document presentation format: Other titles – PowerPoint PPT presentation

Number of Views:129
Avg rating:3.0/5.0
Slides: 20
Provided by: educ5460
Category:
Tags: rsa

less

Transcript and Presenter's Notes

Title: RSA???????


1
RSA???????
  • ????????,?????????RSA???,???????
  • ???????p,q(??512bit)
  • ??????????(?????????).
  • ??npq
  • ??
  • ????e,?
  • ?????? n,e
  • ?????? d ( )

2
RSA???????
  • KeyPairGenerator
  • The KeyPairGenerator class is an engine class
    used to generate pairs of public and private keys
  • Creating the Key Pair Generator
  • try
  • //??KeyPairGenerator??
  • KeyPairGenerator keyGenKeyPairGenerator.getIns
    tance("RSA")
  • System.out.println("Key Test program is ok")
  • catch(NoSuchAlgorithmException e)
  • System.out.println("Error "e.getMessage())

3
RSA???????
  • Initializing the Key Pair Generator
  • SecureRandom random SecureRandom.getInstance(S
    HA1PRNG, SUN) random.setSeed(userSeed)
    //????????,???????
  • keyGen.initialize(1024, random) //???

4
RSA???????
  • The KeyPair Class
  • KeyPair???????????.
  • KeyPair pair keyGen.generateKeyPair()

5
RSA???????
  • The PublicKey Class
  • ???????????(n,e)

6
RSA???????
  • The PrivateKey Class
  • ???????????(n,d,p,q)

7
RSA?????????
  • ??????????????????,??????????????(?10???)?
  • KeyFactory
  • ???????????????????????.
  • //??KeyFactory ??????????
  • RSAPublicKeySpec
  • RSAPrivateKeySpec

8
????RSA??????
  • // ??KeyPairGenerator??
  • KeyPairGenerator keyGen KeyPairGenerator.getInst
    ance("RSA")
  • // ???????
  • SecureRandom random SecureRandom.getInstance("SH
    A1PRNG", "SUN")
  • // ???keyGen?????1024???????
  • keyGen.initialize(1024, random)
  • // ?????
  • KeyPair pair keyGen.generateKeyPair()
  • // ???????????
  • PublicKey puKey pair.getPublic()
  • PrivateKey prKey pair.getPrivate()
  • //????????
  • System.out.println(puKey.toString())
  • System.out.println(prKey.toString())

9
Java???????API
  • Sun RSA public key, 1024 bits
  • modulus( n) 14533458076675335296827162414322
    76429031800268580705381780938426546551318964885088
    59021170467602039725331815700222176862989556902870
    84482393294066468420852304195235606106267419032473
    38842105945430257490034420087727308742868108451005
    51163211606567048423518752061867186661617099735966
    587084128589872797083364747
  • public exponent( e) 65537
  • Sun RSA private CRT(??????) key, 1024 bits
  • modulus(n ) 1453345807667533529682716
    24143227642903180026858070538178093842654655131896
    48850885902117046760203972533181570022217686298955
    69028708448239329406646842085230419523560610626741
    90324733884210594543025749003442008772730874286810
    84510055116321160656704842351875206186718666161709
    9735966587084128589872797083364747
  • public exponent( e ) 65537
  • private exponent( d ) 123650928314896931628818
    18652978058410727398442985115489375977802738781908
    56508959133033468743308685634798161592487962479734
    30327100346926738740536218117730278249237671789995
    77581947427302758151178755242699163508625431533367
    68729876006408930991684033761163675165176902364959
    72293965947291133168132306425021585
  • prime p 128361932237935582979273054284
    96631019420276059582307483685094836716895113592759
    86555886052041544399610367440155992619595177767984
    3538568226126094329161913
  • prime q 113222493797738064807993294815
    84580801659487779713145666093610874564424578061919
    18369426328690536495749517578643835275222390603246
    5534494985244811289566819
  • prime exponent p 914811597881693894168623303857
    04585962748193221372787225609918754068086740402678
    64575090381418803770786186738386857391005381389023
    790468073571745545755305
  • prime exponent q 684497066811141777279628657689
    33987814906169846043386855714322666755735875519370
    73365433353532774844453001508071379135387084866751
    864476949057550209865067
  • crt coefficient 122151313758391817686507891258
    52251387959893277517099645583985397510200970338820
    22847578024232819508295582798491689735541362335865
    4311131059893783646946460

10
??????(???)???
  • //??KeyFactory ??????????
  • KeyFactory keyFactory
  • RSAPublicKeySpec rsaPublicKeySpec
  • RSAPrivateKeySpec rsaPrivateKeySpec
  • //??KeyFactory??
  • keyFactory KeyFactory.getInstance("RSA")
  • //??KeySpec??
  • rsaPublicKeySpec (RSAPublicKeySpec)keyFactory.ge
    tKeySpec(puKey,RSAPublicKeySpec.class)
  • rsaPrivateKeySpec (RSAPrivateKeySpec)keyFactory.g
    etKeySpec(prKey,RSAPrivateKeySpec.class)

11
??????(???)???
  • //??RSA????n,e,d
  • BigInteger nrsaPublicKeySpec.getModulus()
  • BigInteger ersaPublicKeySpec.getPublicExponent()
  • BigInteger drsaPrivateKeySpec.getPrivateExponent(
    )
  • byte array_nn.toByteArray()
  • byte array_ee.toByteArray()
  • byte array_dd.toByteArray()

12
??????(???)???
  • FileOutputStream osnew FileOutputStream("keypair.
    dat")
  • BufferedOutputStream bosnew BufferedOutputStream(
    os)
  • bos.write(array_n.length)
  • bos.write(array_n)
  • bos.write(array_e.length)
  • bos.write(array_e)
  • bos.write(array_d.length)
  • bos.write(array_d)
  • bos.close()

13
RSA??????????
  • //???????
  • FileInputStream isnew FileInputStream("keypair.da
    t")
  • BufferedInputStream bisnew BufferedInputStream(is
    )
  • int rnbis.read()
  • byte arr_nnew bytern
  • bis.read(arr_n)
  • rnbis.read()
  • byte arr_enew bytern
  • bis.read(arr_e)
  • rnbis.read()
  • byte arr_dnew bytern
  • bis.read(arr_d)
  • BigInteger bndnew BigInteger(arr_d)
  • ????,????????????

14
  • package digitalSignature
  • import java.security.
  • import java.security.spec.
  • import java.math.
  • public class TestKeyFactory
  • /
  • _at_param args
  • /
  • public static void main(String args)
  • // TODO Auto-generated method stub
  • KeyFactory keyFactory
  • RSAPublicKeySpec rsaPublicKeySpec
  • RSAPrivateKeySpec rsaPrivateKeySpec
  • PublicKey puKey
  • PrivateKey prKey

15
  • // ?RSAPublicKeySpec ??
  • rsaPublicKeySpec new RSAPublicKeySpec(modulus,
    publicExponent)
  • // ?RSAPrivateKeySpec??
  • rsaPrivateKeySpec new RSAPrivateKeySpec(modulus,
    privateExponent)
  • // ??PublicKey??
  • puKey keyFactory.generatePublic(rsaPublicKeySpec
    )
  • // ??PrivateKey??
  • prKey keyFactory.generatePrivate(rsaPrivateKeySp
    ec)
  • System.out.println(puKey.toString())

16
  • System.out.println(prKey.toString())
  • System.out.println(keyFactory.getProvider().getNam
    e())
  • System.out.println("bit count "
    modulus.bitCount())
  • System.out.println("bit length "
    modulus.bitLength())
  • catch (NoSuchAlgorithmException e)
  • System.out.println(e.getMessage())
  • catch (InvalidKeySpecException e)
  • System.out.println(e.getMessage())

17
SHA???????
  • import java.io.
  • import java.security.
  • import tool.Tools
  • public class TestSHA
  • public static void main(String args)
  • try
  • byte a new byte512
  • int len
  • // ????????
  • FileInputStream in new FileInputStream("GEF-ALL-
    3.2M3.zip")
  • BufferedInputStream read new BufferedInputStream
    (in)

18
SHA???????
  • // ??MessageDigest??
  • MessageDigest sha MessageDigest.getInstance("SHA
    ")
  • while ((len read.read(a, 0, 512)) gt 0)
  • sha.update(a, 0, len)
  • byte hash sha.digest()
  • System.out
  • .println("???????" sha.getDigestLength() 8
    " bits")
  • System.out.println(Tools.toHexString(hash))
  • // ???????
  • in.close()

19
SHA???????
  • System.out.println(sha.getAlgorithm())
  • catch (FileNotFoundException e)
  • System.out.println(e.getMessage())
  • catch (NoSuchAlgorithmException e)
  • System.out.println(e.getMessage())
  • catch (IOException e)
  • System.out.println(e.getMessage())
Write a Comment
User Comments (0)
About PowerShow.com