الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

لماذا لا استطيع تنفيذ الكود التالي ( يختص بالتشفير و فكه )

بدأه فتاة البحر في 12 نوفمبر 2011 · 3 رد · 559 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

هذا الكود الذي عملته

و اسفه سبق و نزلت موضوع مشابه لكني ما صغت السؤال بشكل صحيح ، و ما قدرت اعدل ع الموضوع السابق

هذا الكود :

// Test AES Encryption and Decryption using JCrypto

// usage :
// java AESTest -gen KeyFile
// java AESTest -enc PlainFile CipherFile KeyFile
// java AESTest -dec CipherFile plainFile KeyFile

import com.sudancs.jcrypto.AESCipher ;
import com.sudancs.jFile.FileOperations ;

import java.security.Key ;
import java.io.IOException ;

public class AESTest {
   public static void main (String[] args ) {
      if ( args.length > 0 ) {
         try {
            if ( args[0].equals("-gen") ) {
               AESCipher AES = new AESCipher("AES");
               Key key = AES.getKey();
               FileOperations.writeKeyToDisk( args[1] , key );
            }
            else if ( args[0].equals("-enc") ) {
               Key key = FileOperations.readKeyFromDisk( args[3] );       // read key file
               AESCipher AES = new AESCipher("AES",key);
               byte[] plainText  = FileOperations.readFromDisk( args[1] ) ; // read plain File
               byte[] cipherText = AES.encrypt(plainText) ; 
               FileOperations.writeToDisk( args[2] , cipherText ) ;       // write cipher file
            }
            else if ( args[0].equals("-dec") ) {
               Key key = FileOperations.readKeyFromDisk( args[3] );        // read key file
               AESCipher AES = new AESCipher("AES",key);
               byte[] cipherText  = FileOperations.readFromDisk( args[1] ) ; // read cipher File
               byte[] plainText = AES.decrypt(cipherText) ; 
               FileOperations.writeToDisk( args[2] , plainText ) ;            // write plain file
            }
         }
         catch ( Exception ioe ) {
            ioe.printStackTrace();
         }
      }
      else
         System.out.println("error in usage");
   }
}

انا اريد هذا الكود ان يستعرض ملف مشفر و مفتاح key جاهز عندي

و بالتالي يعطيني النص الاساسي بعد فك التشفير

يعني وظيفته باختصار decrypt

ما هو التعديل الذي يجب ان اضعه في هذا الكود حتى يتم التنفيذ

ارجو منكم الافاده يا اخوه و شكرا

من فضلك... اذكر الله

لا اله الا الله وحده لا شريك له

له الملك و له الحمد و هو على كل شيء قدير

:thumb_up: :clapping:

(f)

#2

وما المشكلة التي تعترض هذه الشيفرة؟

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#3

المشكله اني لا اعرف كيف اضع الامر الذي يقوم بقراءة المسج المشفر و الـ key الموجودة على جهازي

و بالتالي استطيع فك تشفيرها

اتمنى اتمنى ان تقدم لي الفائده :wacko:

من فضلك... اذكر الله

لا اله الا الله وحده لا شريك له

له الملك و له الحمد و هو على كل شيء قدير

:thumb_up: :clapping:

(f)

#4
فتاة البحر كتب:

السلام عليكم

هذا الكود الذي عملته

و اسفه سبق و نزلت موضوع مشابه لكني ما صغت السؤال بشكل صحيح ، و ما قدرت اعدل ع الموضوع السابق

هذا الكود :

// Test AES Encryption and Decryption using JCrypto

// usage :
// java AESTest -gen KeyFile
// java AESTest -enc PlainFile CipherFile KeyFile
// java AESTest -dec CipherFile plainFile KeyFile

import com.sudancs.jcrypto.AESCipher ;
import com.sudancs.jFile.FileOperations ;

import java.security.Key ;
import java.io.IOException ;

public class AESTest {
   public static void main (String[] args ) {
      if ( args.length > 0 ) {
         try {
            if ( args[0].equals("-gen") ) {
               AESCipher AES = new AESCipher("AES");
               Key key = AES.getKey();
               FileOperations.writeKeyToDisk( args[1] , key );
            }
            else if ( args[0].equals("-enc") ) {
               Key key = FileOperations.readKeyFromDisk( args[3] );       // read key file
               AESCipher AES = new AESCipher("AES",key);
               byte[] plainText  = FileOperations.readFromDisk( args[1] ) ; // read plain File
               byte[] cipherText = AES.encrypt(plainText) ; 
               FileOperations.writeToDisk( args[2] , cipherText ) ;       // write cipher file
            }
            else if ( args[0].equals("-dec") ) {
               Key key = FileOperations.readKeyFromDisk( args[3] );        // read key file
               AESCipher AES = new AESCipher("AES",key);
               byte[] cipherText  = FileOperations.readFromDisk( args[1] ) ; // read cipher File
               byte[] plainText = AES.decrypt(cipherText) ; 
               FileOperations.writeToDisk( args[2] , plainText ) ;            // write plain file
            }
         }
         catch ( Exception ioe ) {
            ioe.printStackTrace();
         }
      }
      else
         System.out.println("error in usage");
   }
}

انا اريد هذا الكود ان يستعرض ملف مشفر و مفتاح key جاهز عندي

و بالتالي يعطيني النص الاساسي بعد فك التشفير

يعني وظيفته باختصار decrypt

ما هو التعديل الذي يجب ان اضعه في هذا الكود حتى يتم التنفيذ

ارجو منكم الافاده يا اخوه و شكرا

يجب عليك إستخدام ال Arguments كما هو موضح بالكود ، لعمل ال Key على سبيل المثال

 if ( args[0].equals("-gen") ) {

مثال لإستخدام الكود و فك تشفير ملف :

java AESTest -enc encryptedFile.dat cypherfile KeyFile

الصراحة انا لا إعلم ما هو ال cypherfile ولكن كما هو موضح بالكود فيجب إستخدامة فى المتغيرات

else if ( args[0].equals("-enc") ) {
               Key key = FileOperations.readKeyFromDisk( args[3] );       // read key file
               AESCipher AES = new AESCipher("AES",key);
               byte[] plainText  = FileOperations.readFromDisk( args[1] ) ; // read plain File
               byte[] cipherText = AES.encrypt(plainText) ; 
               FileOperations.writeToDisk( args[2] , cipherText ) ;       // write cipher file
            }

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…