Public key encryption, RSA - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Public key encryption, RSA

Description:

Based on the (assumed) difficulty of factoring large integers ... Provably secure under the random oracle model. M1 = Mask((H(P)|PS|0x01|M),S) M2 = Mask(S, M1) ... – PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 19
Provided by: csU96
Category:

less

Transcript and Presenter's Notes

Title: Public key encryption, RSA


1
Lecture 5
  • Public key encryption, RSA
  • Keys, Keytool, Keystore
  • OpenSSL
  • JAR signing

2
Asymmetric encryption
  • A keypair
  • java.security.PublicKey
  • java.security.PrivateKey
  • One for encryption, one for decryption

3
RSA
  • Rivest, Shamir, Adleman
  • Based on the (assumed) difficulty of factoring
    large integers
  • java.security.interfaces.RSAPrivateKey
  • java.security.interfaces.RSAPublicKey
  • java.security.spec.RSAPrivateKeySpec
  • java.security.spec.RSAPublicKeySpec
  • Example BaseRSAExmple.java

4
KeyFactory
  • java.security.KeyFactory
  • getInstance()
  • generatePublic()
  • generatePrivate()
  • getKeySpec()
  • translateKey()

5
RSAPublicKeySpec
  • RSAPublicKeySpec (RSAPrivateKeySpec) contains
    information needed to generate a public (private)
    key
  • Returns a RSAPublicKey (RSAPrivateKey)
  • BigInteger getModulus()
  • BigInteger getPublicExponent()
  • BigInteger getPrivateExponent() in
    RSAPrivateKeySpec
  • You can pass this to KeyFactory.generatePublic()
  • KeyFactory.generatePrivate() for private key

6
Random RSA keys
  • SecureRandom random new SecureRandom()
  • KeyPairGenerator generator KeyPairGenerator.getI
    nstance("RSA", "BC")
  • generator.initialize(256, random)
  • KeyPair pair generator.generateKeyPair()
  • Key pubKey pair.getPublic()
  • Key privKey pair.getPrivate()
  • ExampleRandomRSAKeyExample.java

7
KeyPairGenerator
  • static  KeyPairGenerator getInstance(String algori
    thm, Provider provider)
  • static KeyPairGenerator getInstance(String algorit
    hm)
  • void initialize(AlgorithmParameterSpec params)
  • void initialize(AlgorithmParameterSpec params,
    SecureRandom random)
  • AlgorithmParameterSpec gives you more control
    over the generated keypair, which is sometimes
    important

8
KeyPairGenerator
  • void initialize(int keysize)
  • void initialize(int keysize, SecureRandom random)
  • KeyPair generateKeyPair()
  • KeyPair genKeyPair()

9
RSAKeyGenParameterSpec
  • Allows you to control the key generation
  • Implements the AlgorithmParameterSpec interface
  • RSAKeyGenParameterSpec(int keysize,
    BigInteger publicExponent)
  • static BigIntegerF0           The
    public-exponent value F0 3.
  • static BigIntegerF4           The public
    exponent-value F4 65537.

10
RSA padding mechanisms
  • RSA handles data as BigInteger
  • Hence leading zeros tend to disappear
  • Example RandomKeyExample.java with added zeros
  • Another problem, what if the input is small and
    the public exponent is small?
  • A padding scheme is needed

11
PKCS1 v1.5 padding
  • Type 1 (when using private key)
  • M 0x000x01F0x00M, where F 0xFF, 0xFF
  • Type 2 (when using public key)
  • M 0x000x02R0x00M, where R is a string of
    random bytes
  • Example PKCS1PaddedRSAExample.java
  • Cipher cipher Cipher.getInstance("RSA/NONE/PKCS1
    Padding", "BC")

12
OAEP
  • Optimal Asymmetric Encryption Padding
  • RSAES-OAEP
  • Provably secure under the random oracle model
  • M1 Mask((H(P)PS0x01M),S)
  • M2 Mask(S, M1)
  • Msg 0x00M2M1
  • where H is a hash function, P is a parameter
    string, S is a random seed, M is the message and
    PS is a padding of zeros. Msg is what is sent.

13
OAEP
  • Example OAEPPaddedRSAExample.java
  • Cipher cipher Cipher.getInstance("RSA/NONE/OAEP
    WithSHA1AndMGF1Padding", "BC")

14
Handling keys in Java
  • Random
  • Your own files
  • Keystore
  • Certificates

15
Keystores
  • For storing asymmetric keys
  • Store
  • Delete
  • List
  • Export/import
  • Make certificate requests
  • Etc.

16
Keytool
  • Tool for
  • Creating
  • Storing
  • Importing/Exporting
  • Managing
  • Keys

17
Keytool
  • usage keytool command options
  • keytool -genkey -keyalg rsa -alias TOHclient
    -keystore client.keystore
  • keytool list keystore client.keystore

18
Keystore example
Write a Comment
User Comments (0)
About PowerShow.com