Simple Encryption

Hi All, I want to encrypt a simple text as given in the example below BUT I am getting 'java.lang.NoSuchMethodError' Exception at the Cipher.getInstance("DES") method.
Please help me or give me some references.
Write me at [email protected]
This is the test code -
Cipher desCipher;
byte[] desKeyData = { (byte)0x01, (byte)0x02, (byte)0x03,..};
SecretKeySpec desKey = new SecretKeySpec(desKeyData, "DES");
// Getting Exception at this point
desCipher = Cipher.getInstance("DES");
desCipher.init(Cipher.ENCRYPT_MODE, desKey);
// Our cleartext
byte[] cleartext = "This is just an example".getBytes();
// Encrypt the cleartext
byte[] ciphertext = desCipher.doFinal(cleartext);
// Initialize the same cipher for decryption
desCipher.init(Cipher.DECRYPT_MODE, desKey);
// Decrypt the ciphertext
byte[] cleartext1 = desCipher.doFinal(ciphertext);

try this:
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.SealedObject;
import java.security.*;
import java.io.*;
import javax.crypto.*;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.KeyAgreement;
import javax.swing.*;
public class encryptTest
public static void main(String args[])
String password = JOptionPane.showInputDialog(null,"Plz Enter Any word to Encrypt");
Security.addProvider(new com.sun.crypto.provider.SunJCE());
try
KeyGenerator kg = KeyGenerator.getInstance("DES");
Key key = kg.generateKey();
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE,key);
byte[] encrypted_password = cipher.doFinal(password.getBytes());
JOptionPane.showMessageDialog(null,"Encrypted Password "+ new String(encrypted_password));
cipher.init(Cipher.DECRYPT_MODE,key);
byte[] decrypted_password = cipher.doFinal(encrypted_password);
JOptionPane.showMessageDialog(null,"Decrypted Password "+new String(decrypted_password));
catch(NoSuchAlgorithmException nsae)
System.out.println("No Such Algorithm Exception " + nsae.getMessage());
catch(NoSuchPaddingException nspe)
System.out.println("No Such Padding Exception " + nspe.getMessage());
catch(InvalidKeyException ike)
System.out.println("Invalid Key Exception " + ike.getMessage());
catch(IllegalStateException ise)
System.out.println("Illegal State Exception " + ise.getMessage());
catch(IllegalBlockSizeException ibse)
System.out.println("Illegal Block Size Exception " + ibse.getMessage());
catch(BadPaddingException bpe)
System.out.println("Bad Padding Exception " + bpe.getMessage());

Similar Messages

  • Simple encryption method

    Hey i am trying to create a simple encryption. This is my function.
    public static String Crypt(String sData)
    byte[] bytes = sData.getBytes();
    for(int i=0; i<bytes.length; i++)
    bytes[i] ^= 477;
    return (new String(bytes));
    Unfortunately the String that is returned has a lot of "???????" in it. I have also tried char arrays but to no effect. I want to be able to send the data using a socket therefore i need it in a char array or string. Can anyone help please?

    >
    return (new String(bytes));
    Unfortunately the String that is returned has a lot of
    "???????" in it. I have also tried char arrays but to
    no effect. I want to be able to send the data using a
    socket therefore i need it in a char array or string.1) Not all byte and byte combinations produce a valid String object so one cannot use 'new String(bytes)' with the certainty of being able to reverse the operation and get back the original bytes. i.e.
    new String(some bytes).getBytes() usually does not return 'some bytes'.
    2) You don't need to have a char array or string to send bytes down a Socket. Just send down the encrypted bytes.
    3) I hope you are not considering this encryption method for an industrial strength application!

  • Simple encryption algorithm

    Hi there,
    Where can i find a very simple encryption algorithm to allow me to encrypt basic strings?
    It should be simple enough so i can make a version for Java and Cobol.
    Thanks for any help.

    I guess you can implement any encryption algorithm with either language. XOR should suffice... just not ROT13, it'll be a pain with EBCDIC. XOR each byte with some byte you randomly picked.

  • Simple Encryption and Simple Question

    Anyway, I hope it is simple!
    This is from an example in my text book, I have coded it up and it works great. I think I understand everything except for the subtraction of 'A' in the encryptMessage method. Any ideas? I thought it may be subtracting the ASCII value of 'A', but isn't that just 1?
    Any help is appreciated.
    public class CeasarCryptography
         public static final int ALPHASIZE = 26; //Standard English alphabet size, ALL uppercase
         public static char[] alpha = {'A','C','B','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
         protected char[] encryptionKey = new char[ALPHASIZE];
         protected char[] decryptionKey = new char[ALPHASIZE];
         public CeasarCryptography()
                   //Initializes encryptionArray
                   for (int x = 0; x < encryptionKey.length; x++)
                             encryptionKey[x] = alpha[ (x + 3) % ALPHASIZE ]; //Rotate alphabet by three places
                   //Initializes encryptionArray and decryptionArray
                   for (int x = 0; x < decryptionKey.length; x++)
                             decryptionKey[encryptionKey[x] - 'A'] = alpha[x]; //Decypt is revers of encrypt
         public String encryptMessage(String secret)
                   char[] mess = secret.toCharArray(); //First, place the string in an array
                   for (int x = 0; x < mess.length; x++)
                             if (Character.isUpperCase(mess[x]))
                                       mess[x] = encryptionKey[mess[x] - 'A'];
                   return new String(mess);
         public String decryptMessage(String secret)
                   char[] mess = secret.toCharArray();
                   for (int x = 0; x < mess.length; x++)
                             if (Character.isUpperCase(mess[x]))
                                       mess[x] = decryptionKey[mess[x] - 'A'];
                   return new String(mess);
         public static void main(String[] args)
                   CeasarCryptography cipherObject = new CeasarCryptography();
                   System.out.println("Welcome to the oldest known enryption program.");
                   System.out.println("\tEncryption Key: " + new String(cipherObject.encryptionKey));
                   System.out.println("\tDecryption Key: " + new String(cipherObject.decryptionKey));               
                   String testString = "JAVA IS NOT EASY";
                   System.out.println("\nEncrypt the following: " + testString);
                   System.out.println("\tOnce encrypted: " + cipherObject.decryptMessage(testString));
    }

    If the value of 'A' is not important, how is 'D' -
    'A' 3? Because D is 3 later than A. So whether 'A' is -123 or 0 or 1 or 65, 'A' + 3 is always 'D'.
    Or is this D (which is the 4th letter) minus A
    (which is the 1st letter) for 4-1 = 3. Right. It's just that in ASCII, 'A' is 65, instead of 1 or 0 that we usually think of it. The whole minus 'A' part is just to say "how far away from A are we, and therfore how much are we shifting?"
    And 3 is the
    element in the Array that D is in?I was winging it here but that's what it comes down to. Whether it's an index into an array where 'A' is in 0, 'B' is in '1', etc., or just an on-the-fly shifting, either way, "minus 'A'" ultimately means "How far away from A is this letter?"

  • Simple encryption question

    i have a very simple user authentication system, where user info is stored in a flat text file on the server. I want to encrypt the password so that it's not stored in plain text, but I can't understand any of the tutorials about security and encryption...is there any way that I can just use a class (or a few) to encrypt the password in the file, then encrypt submitted passwords & check if they match (rather than dealing wiht public and private keys and all that jazz)
    thanks a lot
    Laz

    Instead of encrypting the password you should calculate message digest (i.e. MD5 or SHA).
      java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA");
      md.update( password.getBytes());
      byte[] digest = md.digest();

  • Simple encryption... need help...

    hello friends,
    this may be a simple problem, but, as i m new plz forgive me...
    i have to accept three command line agrumetns like...
    name ---> string
    age ---> integer
    date ---> string
    now, i want to encrypt these data in a two different text files with two different encryption methods...
    and later i need to decrypt the data from both the textfiles...
    can anyone help me how can i achieve this task ???
    Thanks,
    Rohan

    hi arshad,
    thanks for the guidence...
    i just needed the proper direction... not the code...
    Thanks again...
    i went through some books and tried a sample code from a book...
    here is the code...
    package des;
    import java.io.*;
    import java.security.*;
    import javax.crypto.*;
    import sun.misc.*;
    * @author Rohan.Nakar
    public class SecretWriting
         public static void main(String[] args) throws Exception
              //checking argumetns
              if(args.length < 2)
                   System.out.println("Usage: SecureWriting -e | -d plainText");
                   return;
              //get or create key
              Key key;
              try
                   ObjectInputStream in = new ObjectInputStream( new FileInputStream("SecretKey.ser"));
                   key = (Key)in.readObject();
                   in.close();
              catch (FileNotFoundException fnfe)
                   KeyGenerator generator = KeyGenerator.getInstance("DES");
                   generator.init(new SecureRandom());
                   key = generator.generateKey();
                   ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("SecretKey.ser"));
                   out.writeObject(key);
                   out.close();
              //get a cipher object
              Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
              //Encrypt or decrypt the input string
              if (args[0].indexOf("e") != -1)
                   cipher.init(Cipher.ENCRYPT_MODE, key);
                   String amalgam = args[1];
                   for(int i = 2; i < args.length; i++)
                        amalgam += " " + args;
                   byte[] stringBytes = amalgam.getBytes("UTF8");
                   byte[] raw = cipher.doFinal(stringBytes);
                   BASE64Encoder encoder = new BASE64Encoder();
                   String base64 = encoder.encode(raw);
                   System.out.println(base64);
              else if (args[0].indexOf("d") != -1)
                   cipher.init(Cipher.DECRYPT_MODE, key);
                   BASE64Decoder decoder = new BASE64Decoder();
                   byte[] raw = decoder.decodeBuffer(args[1]);
                   byte[] stringBytes = cipher.doFinal(raw);
                   String result = new String(stringBytes, "UTF8");
                   System.out.println(result);
    this is giving me an exception...
    java.security.NoSuchAlgorithmException: Algorithm DES not available
         at javax.crypto.SunJCE_b.a(DashoA6275)
         at javax.crypto.KeyGenerator.getInstance(DashoA6275)
         at des.SecretWriting.main(SecretWriting.java:40)
    Exception in thread "main"
    any help...
    Thanks in advance...

  • Simple Encryption Code help. Why this error?

    Why does the implements Command pharse error this program out
    I am a beginner here so please take it easy. I know it's probably a stupid mistake.
    Also how would I limit the ASCII character conversion to be between 32 and 126.
    public class Caesar {
    implements Command //This line errors out the entire code
    // Inv: true
    private int shift;
    public Caesar(int shift)
    this.shift = shift;
    public String encrypt(String text)
    return shiftCharacterValues(text, shift);
    public String decrypt(String text)
    return shiftCharacterValues(text, -shift);
    private String shiftCharacterValues(String text, int shift)
    StringBuffer encrypted;
    encrypted = new StringBuffer(text);
    for (int i = 0; i < encrypted.length(); i++)
    encrypted.setCharAt(i, (char)(encrypted.charAt(i) + shift));
    return encrypted.toString();
    public static void main(String[] args)
    Caesar caesar;
    String original, encrypted, decrypted;
    caesar = new Caesar(7);
    original = "hello"'
    encrypted = caesar.encrypt(original);
    decrypted = caesar.decrypt(encrypted);
    System.out.println("Original = " + original);
    System.out.println("Encrypted = " + encrypted);
    System.out.println("Decrypted = " + decrypted);
    }

    might be?
    public class Caesar {
      private int shift;
      public Caesar(int shift) {
        this.shift = shift;
      public String encrypt(String text) {
        return shiftCharacterValues(text, shift);
      public String decrypt(String text) {
        return shiftCharacterValues(text, -shift);
      private String shiftCharacterValues(String text, int shift) {
        StringBuffer encrypted;
        encrypted = new StringBuffer(text);
        for (int i = 0; i < encrypted.length(); i++)
             encrypted.setCharAt(i, (char)(encrypted.charAt(i) + shift > 126 ? (encrypted.charAt(i) + shift -95) : (encrypted.charAt(i)+shift < 32 ? (encrypted.charAt(i) + shift + 95) : encrypted.charAt(i) + shift)));
        return encrypted.toString();
      public static void main(String[] args) {
        Caesar caesar;
        String original, encrypted, decrypted;
        caesar = new Caesar(-7);
        original = " hello";
        encrypted = caesar.encrypt(original);
        decrypted = caesar.decrypt(encrypted);
        System.out.println("Original = " + original);
        System.out.println("Encrypted = " + encrypted);
        System.out.println("Decrypted = " + decrypted);
    }

  • Simple encryption applet

    I'm just wondering if somewhere on the web there was any site with the ability to simply input a String, and a salt, and have it encrypt it, or enter a String (encrypted) and the salt used and have it decrypt it. I put applet in the title, but I don't even care if it's in java. I could probably write one myself but first of all I don't want to re-invent the wheel, and second of all I don't want anyone thinking I messed with the program to steal passwords. Thanks.

    Also think of ways of dealing with salt. Typically, it is unwise to use the same encryption key for large volumes of data. One way to somewhat minimize this is for the server to generate a token (salt) and send it to the client. The client uses this token as the salt for the PBE based authentication encryption as well as the encrypted content. The server would send a new token (salt) to the client until the authentication is successful. Once the authentication is successful the token used during authentication (salt) is used until the session is complete or timed out. Thus every time a user comes to your site his/her session key (aka the key derived by PBE using the salt and password) would be different.
    It would also eliminate possible dictionary attacks against your system....

  • Help With Simple Encryption Code

    I'm making a Cipher for personal use and possible publish as freeware. Can someone help me figure out what I'm missing in my code and/or post possible fixes? Thanks!
    P.S. If this code looks ametuer, it's because it is. I'm just a freshman in college :)
    Encryption Class:
    import java.util.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import java.security.*;
    public class EncryptionModule {
    static final int keylength = 42;
    private SecretKeySpec skeySpec;
    public EncryptionModule(String key)
    skeySpec = makeKey(key);
    public SecretKeySpec makeKey(String keys)
    SecretKeySpec skeySpec = null;
    try {
    byte [] keys_raw = keys.getBytes();
    skeySpec = new SecretKeySpec(keys_raw, "Blowfish");
    } catch(Exception e) {
    e.printStackTrace();
    return skeySpec;
    public String EncryptionModule(String line)
    byte[] encrypted = new byte[0];
    try {
    Cipher cipher = Cipher.getInstance("Blowfish");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
    encrypted = cipher.doFinal(line.getBytes());
    } catch(Exception e) {
    e.printStackTrace();
    return new String(encrypted);
    public String Decrypt(String line)
    byte[] decrypted = new byte[0];
    try {
    Cipher cipher = Cipher.getInstance("Blowfish");
    cipher.init(Cipher.DECRYPT_MODE,skeySpec);
    decrypted = cipher.doFinal(line.getBytes());
    } catch(Exception e) {
    e.printStackTrace();
    return new String(decrypted);
    File IO Class:
    import java.io.*;
    import java.awt.*;
    import java.util.*;
    public class FileIO
    BufferedReader inputFile;
    String inputFileName;
    BufferedWriter outputFile;
    String outputFileName;
    ArrayList dataList;
    ArrayList breakLine;
    EncryptionModule EncryptionModuleor;
    * Constructor for objects of class IO.
    public FileIO(String key)
    dataList = new ArrayList();
    breakLine = new ArrayList();
    EncryptionModuleor = new EncryptionModule(key);
    public void main(String[] args) throws IOException
    dataList = new ArrayList();
    breakLine = new ArrayList();
    setInputFile();
    * setInputFile - Displays a dialog box to select and open a file for input
    * @return true if success, false otherwise
    public boolean setInputFile() throws IOException
    boolean fileOpened = true;
    FileDialog myDB = new FileDialog(new Frame(),"Select a log file for INPUT");
    myDB.setDirectory(".");
    myDB.show();
    inputFileName = myDB.getFile();
    if (inputFileName==null){
    fileOpened = false;
    else {
    try {
    inputFile = new BufferedReader(new FileReader(myDB.getDirectory()+"\\"+inputFileName));
    catch(FileNotFoundException e) {
    fileOpened = false;
    return fileOpened;
    * setOutputFile - Displays a dialog box to select and open or create a file for output
    * @return true if success, false otherwise
    public boolean setOutputFile() throws IOException
    boolean fileOpened = true;
    FileDialog myDB = new FileDialog(new Frame(),"Select or create a file for OUTPUT");
    myDB.setDirectory(".");
    myDB.setMode(FileDialog.SAVE);
    myDB.show();
    outputFileName = myDB.getFile();
    if (outputFileName==null){
    fileOpened = false;
    else{
    try {
    outputFile = new BufferedWriter(new FileWriter(myDB.getDirectory()+"\\"+outputFileName));
    catch(FileNotFoundException e) {
    fileOpened = false;
    return fileOpened;
    public void processData()throws IOException
    dataList = new ArrayList();
    if (!setInputFile()){
    System.out.println("Cannot open selected input file: "+inputFileName);
    return;
    String line;
    line = inputFile.readLine(); //Read a new line from the input file
    EncryptionModuleor = new EncryptionModule(line);
    line = inputFile.readLine();
    while(line != null)
    dataList.add(EncryptionModuleor.EncryptionModule(line));
    line = inputFile.readLine(); //Read a new line from the input file
    copyFile();
    public void copyFile() throws IOException
    if (!setOutputFile()){
    System.out.println("Cannot open selected output file: "+outputFileName);
    return;
    for (int i=0; i<dataList.size(); i++){
    outputFile.write((String)dataList.get(i));
    if (i<dataList.size()-1){
    outputFile.newLine();
    outputFile.close();
    }

    You dont say what the problem is so one has to guess!
    1) " return new String(encrypted);"
    It is not realy safe to convert bytes to String this way. This must be close to the number 1 problem seen in this forum. Use something like Base64 or HEX encoding.
    2) Don't just catch exceptions and print out stack traces!
    If you intend to publish the encrytpion class then define an exception class specific to this problem (maybe more than one) and convert internal exceptions that you can't handle to this exception.
    3) You ave not defined a mode or padding and are relying on the default. Make it explicit so there is no argument as to what mode and padding is being used.
    4) For some reason you are breaking a file into lines and then encrypting each line. Why not just encrypt the whole file as bytes. Much easier, quicker, less code.
    5) Rather than use a GUI to select the file why not make them command line parameters using the standard UNIX/DOS approach.

  • Simple asymmetry in XOR-type encryption

    Hi there.
    In my never-ending quest for knowledge, I've decided to implement a (very) simple and (very) weak encryption algorithm, to teach myself the extreme basics of cryptography. What I decided to do is this:
    Take a byte array, which could represent a file, or user input, or whatever, and XOR each byte with a byte from an encryption key provided by the user.
    This produces a garbled set of bits that represent the encrypted message. This also has the (dis)advantage that decryption is the same process as encryption, since XOR is symmetric. So in order to decrypt an encrypted message, you simply supply the same encryption key, and re-encrypt it. This is the code:
    public static byte[] encryptOrDecrypt(byte[] key, byte[] data)
         byte[] digest = new byte[data.length];
         for (int i = 0; i < data.length; i++)
              digest[i] = new Integer(key[i % key.length] ^ data).byteValue();
         // wipe the arrays for security.
         Arrays.fill(key, (byte) 0x00);
         Arrays.fill(data, (byte) 0x00);
         return digest;
    }Note also that I am blanking the key and data arrays so they do not remain in memory. Perhaps overkill for such a simple encryption, but it seems like a good habit to get into.
    Now that works just fine; the encryption and decryption produce the proper output. However, I would like the encryption and decryption processes to be different, so that if the user wanted to double-encrypt a file, it wouldn't produce just a decrypted file as output. My idea was this:
    First encrypt with a static array of nothing-up-my-sleeve bytes (which I called a Rubicon), then encrypt with the user's encryption key.
    Thus to decrypt, just decrypt with the user's encryption key, then with the Rubicon.private static byte[] RUBICON = {0x08, 0x29, 0x3A, 0x4B, 0x5C, 0x6D, 0x7E, 0x0F};
    public static byte[] encrypt(byte[] key, byte[] data)
         byte[] digest = new byte[data.length];
         for (int i = 0; i < data.length; i++)
              digest[i] = new Integer(RUBICON[i % RUBICON.length] ^ data[i]).byteValue();
         for (int i = 0; i < data.length; i++)
              digest[i] = new Integer(key[i % key.length] ^ digest[i]).byteValue();
         // wipe the arrays for security.
         Arrays.fill(key, (byte) 0x00);
         Arrays.fill(data, (byte) 0x00);
         return digest;
    // and the decrypt method would work in the reverse
    I thought I was being pretty clever. Turns out that because of the symmetry of XOR, it doesn't matter whether you use the Rubicon or user's key first, you'll get the same output.
    I am trying to think of a way that is simpler than RSA-level algorithms, but more realistically secure than a Caesar cipher (example: shifting 1 byte right on encryption, then 1 byte left on decryption is way too simple). Any ideas for methods to differentiate between encryption and decryption, while staying simple but not too simple?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Well, what I m searching for is something like:
    needs-client-auth="if-cert-exists"
    (i.e. when I set my secure-web-site.xml settings, in the ssl-config entity.)
    I'm new to OC4J and got no idea if this possible. I know that this can be at least done in Tomcat and Weblogic.
    By applying the settings as:
    Tomcat => clientAuth="want"
    and
    Weblogic => Two Way Client Cert Behavior = "Client Certs Requested But Not Enforced"
    Please advice, how to solve this in Oracle products ?
    Thank you

  • Simple String Encryption

    HI,
    I have been serching around on here for encyption methods but there seems to be soo many i not sure which ones would be good for me.
    All i want to do is encypt and decrypt a String record. The encryption doesnt have to be particulary safe but must work for all possible charaters. Basically i am saving records to a text file and i dont want someone to be able to open the text file and read the contents.
    I would like to make it as simple as possible so i can just use it like:
    String record = "This is the record";
    // Encrypted Record
    String encRecord = Encryption.encrypt(record);
    // Decripted Record
    String decRecord = Encryption.decrypt(record);Can anyone stear me in the right direction or give me some sample code i can study.
    Thank you in advance
    ed

    Here is simple encryption routine that I just wrote that I bet would keep someone
    stumped for a while.
    * This is a simple encryption class that uses simple character substitution.
    * To keep the pattern from being obvious the shift factor is a function of the current character's
    * position in the source string. This makes sure that all letters aren't encrypted to the same value.
    * Usage: To encrypt a string just pass it to the encrypt method.
    *         String encryptedString = Encryptor.encrypt("Some string.");
    *        To decrypt a string just pass the encrypted string to the decrypt method.
    *         String decryptedString = Encryptor.decrypt(encryptedString);
    class Encryptor
      static final byte [] shiftFactor = {2,5,7,9,13,17,19};
      static final int modulo = shiftFactor.length;
      static public String encrypt(String s)
         char [] ba = s.toCharArray();
         for (int i = 0; i < ba.length; i++)
              ba[i] += shiftFactor[i%modulo];
        return new String(ba);
      static public String decrypt(String s)
         char [] ba = s.toCharArray();
         for (int i = 0; i < ba.length; i++)
              ba[i] -= shiftFactor[i%modulo];
         return new String(ba);
      public static void main(String [] args)
         String [] test = {"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz,./<>?;':\"[]{}-=_+!@#$%^&*()`~",
                           "Now is the time for all good men \n to come to the aid of their country."};
        for (int i = 0; i < test.length; i++)
              System.out.println(test);
              String encrypted = Encryptor.encrypt(test[i]);
              System.out.println(encrypted);
              System.out.println(Encryptor.decrypt(encrypted) + "\n");

  • Im dropping a cookie with userid. Can I encrypt it somehow???

    I would like to encypt my cookie. Does anyone have any idea on how to do it.
    Thanks in advance

    You can do pretty much what you want with it. It is easy enough to create your own simple encryption algorithm for a number like a userid. An alternative is to use a session variable that is matched to the user id on the server side and times out after a short while. That way even if someone does read the cookie from your client machine it is useless to them.

  • How to load a ByteArray FLV in OSMF?

    I'm working on a local application ( it's not a website or nothing related ) and I have various FLVs with a very simple encryptation method (just like adding 10 at each byte).
    I can load/play them using NetStream.appendBytes() after my decrypt, but that happens only after I read all video data.
    What I really need is to stream those videos from a remote url, and decrypting while receiving data, using a OSMF player that I already have.
    This is my current code just to play my decoded FLV byte array
    private function playBytes(bytes:ByteArray):void
                // detecting it's header
                if (bytes.readUTFBytes(3) != "FLV")
                    _text.appendText("\nFile \""+ file +"\" is not a FLV")
                    return void;
                bytes.position = 0;
                netConnection.connect(null);
                netStream = new NetStream(netConnection);
                netStream.client = { onMetaData:function(obj:Object):void { } }
                video.attachNetStream(netStream);
                addChild(video);
                // put the NetStream class into Data Generation mode
                netStream.play(null);
                // before appending new bytes, reset the position to the beginning
                netStream.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
                // append the FLV video bytes
                netStream.appendBytes(bytes);
    [I moved the discussion from OSMF, to here, due the lack of attention there]

    I looked at it a couple of month ago and, frankly, don't remember exact package that takes care of it. I don't have OSMF code on this machine - so I cannot look into it now.
    I doubt there are many resources on the web regarding this. This is a very specialized functionality and very few people attempted to do what OSMF does. We have figured out certain aspects but were not able to completely replicate it. Again, it is a very daunting task to search of byte offsets and match with file format specs.

  • Loop won't increment to next line

    My assignment is to do a simple encryption (A-->F,G-->L, etc.) My program will do the encryption, but will only read one line of the text document. How do I get it to read all the lines?
    Assigned text doc.:
    A long time ago there was a young boy
    who went to town 2 buy
    some bread? Yes, some bread!
    0ne ,abcdefgHIjklmnopq, is this a word?
    Fin.
    Current output of my program:
    F qtsl ynrj flt ymjwj bfx f dtzsl gtdi?
    (This is based on a 5 letter incrementation. I'm not sure where the "i?" at the end of the sentance are coming from. They aren't in the text doc.)
    //Matthew Bogard - Project 1
       import java.io.*;
       import java.util.*;
       import java.lang.*;
    //This program takes a text file and encrypts it using a simple encryption.
    //Then it prints the encryption to another text file.
        public class EncryptIt
           public static void main(String[] args)
                               throws FileNotFoundException
             String FileName, OutFileName;
             String AString;
             int numberOfPositions;
             Scanner console = new Scanner(System.in);
             System.out.println("Please enter the File Name to encrypt: ");
             FileName = console.next();
             Scanner InFile = new Scanner(new FileReader(FileName));
             System.out.println("Please enter the File Name that will accept the encrypted file: ");
             OutFileName = console.next();
             PrintWriter OutFile = new PrintWriter(OutFileName);
             System.out.print("Enter an integer for the number of shifts in the encryption: ");
             numberOfPositions = console.nextInt();
             char X;
             int positionNumber = 0;
             int len;
             while (InFile.hasNext()) //I have tried hasNext and hasNextLine
                AString = InFile.nextLine();
                len = AString.length();
                while (positionNumber < len)
                   X = AString.charAt(positionNumber);
                   if ((X >= 65) && (X <= 90))
                      X += numberOfPositions;
                      if (X > 90)
                         X = (char) ((X - 90) + 65 - 1);
                         OutFile.print(X);
                      else
                         OutFile.print(X);
                   else if ((X >= 97) && (X <= 122))
                      X += numberOfPositions;
                      if (X > 122)
                         X = (char) ((X - 122) + 97 - 1);
                         OutFile.print(X);
                      else
                         OutFile.print(X);
                   else
                      OutFile.print(X);
                   positionNumber++;
             InFile.close();
             OutFile.flush();
             OutFile.close();
       }

    Your code is really hard to read. It should be broken down into methods.
    I see your problem though.
    while (InFile.hasNext()) //I have tried hasNext and hasNextLine
                AString = InFile.nextLine();
                len = AString.length();
                // ADD THESE LINES
                System.out.println("Just read len " + len + " for line: " + AString);
                System.out.println("positionNumber is " + postionNumber);
                while (positionNumber < len)
                   X = AString.charAt(positionNumber);
                   if ((X >= 65) && (X <= 90Also, "AString" is a really bad variable name. It should start with lowercase, as per the java convention, and it should have a more descriptive name, like "line" or something.

  • Bitwise operators in XSLT:-

    Hi ,
    Does XSLT has support for BITWISE operations, If so Can you please help me out of that >
    If not , Is there any other way to apply BITWISE logic to the flow in the BPEL.
    I tried it using Java Embedded activity in the BPEL, but I am getting the following Exception SCAC-50012,tried referring to this Exception, but not able to get the exact view of that error., as this activity in the BPEL doesnt have JAVA editor I am not able to point out the same.

    Hi everybody,
    I have the following queries in JAVA.
    1)Is "Operator Overloading" is nothing but
    but "Method Overloading" in Java?There's no operator overloading in Java. For example + can't be changed to mean something else.
    2)Regarding BitWise Operators, i just wanna have
    have an simple example abt the usage of bitwise
    operators. i.e., in real world where we will be using
    these ?Just one example of many is the use of bitwise XOR in simple encryption/decryption. The scheme is called XOR scrambling.
    byte key = 0x77; // a key byte 0101 0101
    byte any = ......; // any byte to be scrambled
    byte scramble = key ^ any; // the scrambled byte
    byte unscramble = key ^ scramble; // unscramble == any, the original byte is back againIt builds on the fact that if you XOR any byte with a bit pattern (key) two times you get the original byte back again.

Maybe you are looking for

  • Using the FCB1010 direct, or through an Interface

    Hi, I am wish to use my Mac to create the effects I wish to use for my playing (guitar) with Logic and Mainstage. I will need a foot controller, so I am considering the FCB 1010 (as many have). I will also be purchasing an interface which will allow

  • HZ API Error

    I am getting the below error when trying to update customer account site using public api. This record in table hz_cust_acct_sites cannot be locked as it has been updated by another user I searched through metalink and could not find any solution. Ca

  • Adobe help stinks - Any good third party manuals?

    I've just purchased CS6 Extended, and I see that the only help I can get is online help, rather than a good, searchable help file, as in earlier versions. It seems they feel they can eliminate the pay checks of technical writers by having their devel

  • Current User for a task Item

    Hi, I have created a sharepoint designer workflow for a document library and task is assigned to sharepoint group. I want to update a column in document library with the user's name who approved the task from sharepoint group. I tried with "Workflow

  • Very Large Site

    In my current environment I have the following setup: I have 1 content database assigned to a Web Application which has a single site collection with a single site. The content database  is 190 GB. Is there a process to split the content database int