Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i implement rsa encryption in java but cipher.final in decript mode doesn't accept any byte encoding expect iso-8859-1 i solve to convert utf-8 to iso-8859-1 and vice-vesa but is there
a way to convert from iso-8859-1 to windows-1256 or convert utf-8 to win-1256 or other strong
encryption and decryption technique
Posted
Comments
Sergey Alexandrovich Kryukov 15-Jun-14 20:50pm    
It has nothing to do with "encryption".
—SA

I don't get you : a text encoding is not, in any way, a cryptographic algorithm; a text encoding represents the way the computer stores the bytes representing a text.
Changing an encoding is as trivial as
C#
byte[] originalBytes; // Here the sequence of bytes representing the UTF-8 encoded string
Encoding enc = Encoding.GetEncoding("windows-1256");
byte[] newBytes = enc.GetBytes(Encoding.UTF8.GetString(originalBytes));

More on this here: Encoding Class[^].

But what I don't get is the relation of a text-encoding with a RSA encryption. An encryption algorithm accepts an array of bytes as input; how you got this array of bytes (i.e., which text encoding you used, if you are trying to encrypt some text) is not the concern of the algorithm.

So I believe you should try to explain better what you are trying to do.

[Edit] Sorry for having missed your tag.
For Java:
Java
byte[] originalBytes; // Here the sequence of bytes representing the UTF-8 encoded string
byte[] newBytes = new String(originalBytes, "UTF8").getBytes("Windows-1256");

That does not change the fact that string encoding must not be confounded with encryption. Even if they share their first three letters, they are not related in any way.
[/Edit]
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 15-Jun-14 20:51pm    
5ed.
—SA
Mahmoud_Gamal 16-Jun-14 5:15am    
this in C# i want in java
Sergey Alexandrovich Kryukov 16-Jun-14 8:38am    
Oops!
—SA
Bernhard Hiller 16-Jun-14 2:38am    
I doubt that your answer is really useful: the guy talked about JAVA!
How to get the bytes from a string in Java?
How does the encryption library look like which he uses (perhaps it does really expect a text in a specific *encoding* as an input instead of a byte array)?
Mahmoud_Gamal 19-Jun-14 3:40am    
yes exactly i mean it :)
thanks
i implement another encryption and decryption for this encoding i want to make it so difficult
here this code

C#
    arrc ="FKRSD$Z%T=!~#_@OJEH/Q*+}YU^-,&()][:|.÷×;";
    arr  ="abcdefghijklmnopqrstuvwxyz_- @0123546798";

public String Mts_encript(String data)
{
 
   StringBuilder builder = new StringBuilder();
   Random r = new Random(25);
   int seed = GregorianCalendar.getInstance().getTime().getSeconds()%27;
   //seed = r.nextInt(9);
   for(int i=0;i<seed;i++)
   {
       //builder.append(arr.charAt(r.nextInt(25)));
           builder.append(arrc.charAt(r.nextInt(25)));

   }
   builder.append(seed);
   seed = builder.length();

  builder.append(arrc.charAt(seed));
  builder.append(arrc.charAt(seed));
  builder.append(arrc.charAt(seed));
   builder.append(data.length());
   seek = 0;
   if(data.length()>9)
       seek = 1;

   int h;
    for(int j= 0; j<data.length();j++)

    {
              for(int i = 0; i<arr.length();i++)

            {

              if(arr.charAt(i) ==data.toLowerCase().charAt(j))
              {
                   //h = ;
                builder.append(arrc.charAt(i));
                break;
              }

            }

    }
    builder.append("'");
     for(int i=0;i<seed;i++)
   {
       //builder.append(arr.charAt(r.nextInt(25)));
           builder.append(arrc.charAt(r.nextInt(25)));

   }


      return builder.toString();
}
public String  Mts_Decript(String data)
{
    data = data.toLowerCase();
      
    StringBuilder builder = new StringBuilder();
    int dataoffset = data.length();
    int i1 = 0;
    for( i1 =0;i1<data.length();i1++)
    {
        if(data.charAt(i1)>='0' &&data.charAt(i1)<='9')
        {
         
            dataoffset =Integer.parseInt( data.substring(i1,i1+1));
            if(data.charAt(i1+1)>='0' &&data.charAt(i1+1)<='9')
            dataoffset =Integer.parseInt( data.substring(i1,i1+2));
            
            
            break;
         }
    }
    ////////////////
    int length = 0;
    i1++;
    i1++;
    ///////////////////////
       for( ;i1<data.length();i1++)
    {
        if(data.charAt(i1)>='0' &&data.charAt(i1)<='9')
        {
         
           length =Integer.parseInt( data.substring(i1,i1+1));
            if(data.charAt(i1+1)>='0' &&data.charAt(i1+1)<='9')
            length =Integer.parseInt( data.substring(i1,i1+2));
            
            
            break;
         }
    }
 
    ///////////////////
    int idex = 0;
    for(int j = dataoffset+5+seek;j<data.length()-dataoffset-1;j++)
    {
      //  arrc.charAt(i)
        idex = arrc.indexOf(data.toUpperCase().charAt(j)); 
        if(idex!=-1 && builder.length()<length)
        {
          builder.append(arr.charAt(idex));
        }
        
        
    }
    return builder.toString();
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900