IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Sécurité Java Discussion :

cryptage Rsa coté mobile et decryptage coté serveur


Sujet :

Sécurité Java

  1. #1
    Futur Membre du Club
    Inscrit en
    Avril 2007
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 3
    Par défaut cryptage Rsa coté mobile et decryptage coté serveur
    salu ,
    j'ai un midlet qui crypte des données bancaires avec Rsa on utilisant un clé public construite à partir du son modulus et son exponent fixes:
    un peu de code de la midlet :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    ///formulaire de paiement
    f2 = new Form("Formulaire de paiement");
    			f2.setTicker(ticker);
    			montant = new TextField("Montant à payer(TND):", "", 16,
    					TextField.ANY);
    			num_Carte = new TextField("Numéro de carte bancaire:", "", 16,
    					TextField.PHONENUMBER);
    			sti = new StringItem(null, "Date d'expiration");
    			date_expjour = new TextField("Jour:     ", "", 2,
    					TextField.PHONENUMBER);
    			date_expmois = new TextField("Mois:     ", "", 2,
    					TextField.PHONENUMBER);
    			date_expannee = new TextField("Année:  ", "", 4,
    					TextField.PHONENUMBER);
    			code_Secret = new TextField("Code secret:", "", 4,
    					TextField.PHONENUMBER);
    			trois_chiff = new TextField("Trois derniers chiffres:", "", 3,
    					TextField.PHONENUMBER);
    			f2.append(montant);
    			f2.append(num_Carte);
    			f2.append(sti);
    			f2.append(date_expjour);
    			f2.append(date_expmois);
    			f2.append(date_expannee);
    			f2.append(code_Secret);
    			f2.append(trois_chiff);
    			display.setCurrent(f2);
    			f2.addCommand(backCommand);
    			f2.addCommand(send);
    			f2.setCommandListener(this);
    //construction de la clé et cryptage
     String modulus="AM8sVwRf8AnUjVpImOQuB5lKYDtzlHJMcQ0aRi2zFh2Jd+V0J8UhpIU1OnIBCj5SW1+L34hWqLmibFwv34XNxC0=";
    String publicExp="AQAB"
    String s1 = montant.getString();
    				String s2 = num_Carte.getString();
    				String s3 = date_expjour.getString();
    				String s4 = date_expmois.getString();
    				String s5 = date_expannee.getString();
    				String s6 = code_Secret.getString();
    				String s7 = trois_chiff.getString();
    				String date_exp = s3 + s4 + s5;
    				String messageClair = s1 + ":" + s2 + ":" + date_exp + ":"+s6+ ":" + s7;
    				System.out.println("message à chiffrer  " + messageClair);
    				BigInteger modulus1 = new BigInteger(1,Base64.decode(modulus));
    				BigInteger pubExp1 = new BigInteger(1,Base64.decode(publicExp));
    				RSAPublicKey= new RSAKeyParameters(false,modulus1,pubExp1)
    byte[] messEnvoyeByte = null;
    				try {
    					messEnvoyeByte = theEncryption.RSAEncrypt(messageClair.getBytes(), RSAPublicKey);
    				} catch (Exception e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				} 
    String messageFinal= new String(Base64.encode(messEnvoyeByte));
    sendSms = new SendSMS();
    sendSms.setMessageEnv(messageFinal);
     
     
    puis lorsque l'sms ARRIVE AU SERVEUR je construi le clé privé et je prend le contenu du sms  ,je le decode puis je le decrypte :
    //code coté serveur
    String modulus = "AM8sVwRf8AnUjVpImOQuB5lKYDtzlHJMcQ0aRi2zFh2Jd+V0J8UhpIU1OnIBCj5SW1+L34hWqLmibFwv34XNxC0=";
     
     String publicExp="AQAB";
     
     String privateExp = "W8C2dTCMHb5uL/sRA5XDNcez4QCqUQi71OK7DAhRlhh8mn6eBuNKFRwrGBsoiX+jX2xWN45qsaRAokxsq/zqoQ==";
     
     String p = "APOXRvd/v4SRQlR+pJxF3b5xbb7EQMjlrNNqAzLdnFJp";
     
    String q = "ANm6IZOtNZfN3KcGxYgZLRWGdYB9fBY/Kq63uVX2NaMl";
     
    String dp = "ANK/tmGZwBw1BPtPmqGt/NyxDG85Ioft1moPVXcjrwTJ";
     
     String dq = "AItBtooaxeVzQQb/mMXkvGZBGtR07jHYcvdPAVaO5F2V";
     
     String qInv = "G/c6jrV1a7m5f+I/qb1eZYVqvxloT6WSDz4QEYduAFQ=";
    //construction de la clé privée
      BigInteger modulus1 = new BigInteger(1,Base64.decode(modulus));
    			  BigInteger pubExp1 = new BigInteger(1,Base64.decode(publicExp));
    			  BigInteger privExp1 = new BigInteger(1,Base64.decode(privateExp));
    			  BigInteger p1 = new BigInteger(1,Base64.decode(p));
    			  BigInteger q1 = new BigInteger(1,Base64.decode(q));
    			  BigInteger dp1 = new BigInteger(1,Base64.decode(dp));
    			  BigInteger dq1 = new BigInteger(1,Base64.decode(dq));
    			  BigInteger qInv1 = new BigInteger(1,Base64.decode(qInv));
    			  RSAPrivateKey=new RSAPrivateCrtKeyParameters(modulus1,pubExp1,privExp1,p1,q1,dp1,dq1,qInv1);
    //recuperation du contenu du sms puis decryptage
    //messageChiffCode64: contenu du sms codé64
      theEncryption= new Encryption();
    			byte[] messageChiffDecode64 = Base64.decode(messageChiffCode64);
    			String s= new String(messageChiffDecode64);
    			System.out.println("message decodé : " + s);
    			byte[] messageDecrypByte = theEncryption.RSADecrypt(messageChiffDecode64, RSAPrivateKey);
    			String messageDecrypFinal = new String(messageDecrypByte);
    			System.out
    					.println("Message Decrypté final : " + messageDecrypFinal);
     
     
    le cryptage coté mobile marche trés bien mais quand je decrypte coté serveur lerreur suivante saffiche :
    javax.servlet.ServletException: unknown block type
    	org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
    	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
    	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
     
     
    le code de la classe Encryption est le suivant:
     
    	public byte[] RSAEncrypt(byte[] toEncrypt,RSAKeyParameters RSAPublicKey) throws Exception {
    		if (RSAPublicKey == null) {
    			throw new Exception(
    					"Please generate RSA keys first in order to work");
    		}
     
    		AsymmetricBlockCipher theEngine = new RSAEngine();
    		theEngine = new PKCS1Encoding(theEngine);
    		theEngine.init(true, RSAPublicKey);
    		return theEngine.processBlock(toEncrypt, 0, toEncrypt.length);
    	}
     
    	public byte[] RSADecrypt(byte[] toDecrypt,RSAPrivateCrtKeyParameters RSAPrivateKey) throws Exception {
    		if (RSAPrivateKey == null) {
    			throw new Exception(
    					"Please generate RSA keys first in order to work");
    		}
     
    		AsymmetricBlockCipher theEngine = new RSAEngine();
    		theEngine = new PKCS1Encoding(theEngine);
    		theEngine.init(false, RSAPrivateKey);
    		return theEngine.processBlock(toDecrypt, 0, toDecrypt.length);
    	}

    svp quelq'un qui maide car j'ai passé une semaine en essayant à franchir le prob mais jai echoué.
    merci pour votre aide

  2. #2
    Futur Membre du Club
    Inscrit en
    Avril 2007
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 3
    Par défaut
    salu,
    le probleme persiste avec moi depuis 10 jours,
    il nya personne qui repond et essaie de resoudre ce probleme.

Discussions similaires

  1. [Débutant] Problème encodage coté client et récupération côté serveur
    Par Pataud dans le forum Développement Web en Java
    Réponses: 3
    Dernier message: 05/11/2013, 17h50
  2. Lien entre cookies coté client et sessions coté serveur
    Par 123quatre dans le forum Langage
    Réponses: 1
    Dernier message: 24/12/2009, 19h26
  3. Validation d'un formulaire coté client et/ou coté serveur
    Par antrax2013 dans le forum Général Conception Web
    Réponses: 4
    Dernier message: 12/07/2006, 17h03
  4. [Concept] Curseur coté client et curseur coté serveur
    Par freud dans le forum Décisions SGBD
    Réponses: 2
    Dernier message: 13/09/2002, 23h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo