如何转换utf-8至windows-1256 [英] how to convert from utf-8 to windows-1256
问题描述
我在java中实现了rsa加密,但是在decript模式下cipher.final不接受任何字节编码我希望iso-8859-1解决将utf-8转换为iso-8859-1和副vesa但是
a方式从iso-8859-1转换为windows-1256或将utf-8转换为win-1256或其他强大的
加密和解密技术
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
推荐答案
我没有得到你:文本编码不以任何方式加密算法;文本编码表示计算机存储表示文本的字节的方式。
更改编码与
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
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));
更多相关信息:编码类 [ ^ ]。
但我得不到的是文本编码与RSA加密的关系。加密算法接受一个字节数组作为输入;如何获得这个字节数组(即,你使用哪种文本编码,如果你试图加密某些文本)不是算法的关注点。
所以我相信你应该试着更好地解释你想要做什么。
很抱歉错过了你的标签。
For Java:
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.
Sorry for having missed your tag.
For Java:
byte[] originalBytes; // Here the sequence of bytes representing the UTF-8 encoded string
byte[] newBytes = new String(originalBytes, "UTF8").getBytes("Windows-1256");
这不会改变字符串编码不能与加密混淆的事实。即使他们分享前三个字母,它们也没有任何关联。
[/ Edit]
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]
我为这个编码实现了另一个加密和解密想要让它变得如此困难
这里这段代码
i implement another encryption and decryption for this encoding i want to make it so difficult
here this code
arrc ="FKRSD
Z%T =!〜#_ @ OJEH / Q * +} YU ^ - ,& ;安培;()] [:|÷×;跨度>;
arr = abcdefghijklmnopqrstuvwxyz_- @ 0123546798;
public String Mts_encript(字符串数据)
{
StringBuilder builder = new StringBuilder();
随机r = 新随机( 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(字符串数据)
{
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)> = ' < span class =code-string> 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();
}
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(); }
这篇关于如何转换utf-8至windows-1256的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!