开发者

encryption program

i need some idea for creatin a encryption program can any one help!? i need to create the program in java or c++ so need to create a logic for it this encryption prog should automatically encrypt the document n should decrypt it only if the givien conditions such as the passwo开发者_运维问答rd are fulfilled ! plz help !


If its homework, you can do simple XOR with your pwd. Otherwise DONT! DONT mess with security stuff, DONT invent your own algo and DONT use ur own implementation of some well known methods. DO use something that has proven to be safe already.


I agree with fielding. in case you want to do your homework, I think it's OK to use XOR encryption:

Java Sample Code:

public String xorEnc(int encKey, String toEnc) {
    /*
        Usage: str = xorEnc(integer_key,string_to_encrypt);
        Created by Matthew Shaffer (matt-shaffer.com)
    */
    int t=0;
    String s1="";
    String tog="";
    if(encKey>0) {
        while(t < toEnc.length()) {
            int a=toEnc.charAt(t);
            int c=a ^ encKey;
            char d=(char)c;
            tog=tog+d;
            t++;
        }

    }
    return tog;
}
public String xorEncStr(String encKey, String toEnc) {
    /*
        Usage: str = xorEnc(string_key,string_to_encrypt);
        Created by Matthew Shaffer (matt-shaffer.com)
    */
    int t=0;
    int encKeyI=0;

    while(t < encKey.length()) {
        encKeyI+=encKey.charAt(t);
        t+=1;
    }
    return xorEnc(encKeyI,toEnc);
}

you may want to start the decryption process only if the correct password entered, then you should somehow store the hash of decryption password on the encrypted file. for example your encrypted file may look like this:

[MD5 HASH OF PASSWORD][Encrypted Data]

then compare the entered password hash with the one you have saved, if they're identical start decryption process.


if you like to do more advanced encryption/decryption you can have a look at nms-c/nms-d ( found at dotlike.net/releases.php )

it uses libcrypto and decrypts commands sent from a client (nms-c) and executes the command end send the encrypted output back to the client and prints it.

it uses base64-encoding/decoding before to transfer everything correctly.

blowfish encrypted is used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜