Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
blackberry中的AES算法_Blackberry_Encryption_Java Me_Aes - Fatal编程技术网

blackberry中的AES算法

blackberry中的AES算法,blackberry,encryption,java-me,aes,Blackberry,Encryption,Java Me,Aes,我正在用黑莓手机做一个应用程序。在该应用程序中,我希望使用AES算法加密字符串。有可能在黑莓中使用AES算法吗?有什么API吗?提前感谢,查看和(在谷歌的帮助下)。查看和(在谷歌的帮助下)。试试这个- useremail= CryptAes.AESEncryption(username_.getBytes()); 下面给出了CryptAes类- public class CryptAes { // First create the AES key based on the bytes in s

我正在用黑莓手机做一个应用程序。在该应用程序中,我希望使用AES算法加密字符串。有可能在黑莓中使用AES算法吗?有什么API吗?提前感谢,

查看和(在谷歌的帮助下)。

查看和(在谷歌的帮助下)。

试试这个-

useremail= CryptAes.AESEncryption(username_.getBytes());
下面给出了CryptAes类-

public class CryptAes {
// First create the AES key based on the bytes in secretKey using  keyLength bits as the length
static AESKey keydec = new AESKey("A3$1E*81234567891111111111111111".getBytes() );
static AESKey keyenc = new AESKey("A3$1E*81234567891111111111111111".getBytes() );
static AESKey keyenc128 = new AESKey("A3Q1EF8123456789".getBytes());
static AESKey keydec128 = new AESKey("A3Q1EF8123456789".getBytes());

private static byte[] iv = { 0x0a, 0x01, 0x02, 0x03, 0x04, 0x0b, 0x0c,
    0x0d, 0x0a, 0x01, 0x02, 0x03, 0x04, 0x0b, 0x0c, 0x0d };

public static byte[] plainText= new byte[10000];

public static String AESEncryption(byte[] plainText) throws CryptoException, IOException {
      AESEncryptorEngine engine = new AESEncryptorEngine( keyenc128 );
      CBCEncryptorEngine cengine=new CBCEncryptorEngine(engine, new InitializationVector(iv));
      PKCS5FormatterEngine fengine = new PKCS5FormatterEngine( engine );
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      BlockEncryptor encryptor = new BlockEncryptor( fengine, output );

      encryptor.write(plainText);
      encryptor.close();
      byte[] encryptedData = output.toByteArray(); output.close();
      String st=new String(encryptedData);

      byte[] base64 = Base64OutputStream.encode(encryptedData, 0, encryptedData.length, false, false);

        //Base64Coder.encodeString(Byte.toString(plainText));
        String str = new String(base64);

   return str;
}


// sampleAESDecryption
public static String AESDecryption(byte[] cipherText, int dataLength ) throws CryptoException, IOException {

    // Create the input stream based on the ciphertext
    ByteArrayInputStream in = new ByteArrayInputStream( cipherText, 0, dataLength );

    // Now create the block decryptor and pass in a new instance
    // of an AES decryptor engine with the specified block length
    BlockDecryptor cryptoStream = new BlockDecryptor(new AESDecryptorEngine( keydec128 ), in );

    byte[] T= new byte[dataLength];
    // Read the decrypted text from the AES decryptor stream and
    // return the actual length read

    int length= cryptoStream.read( T );
  String str= new String(T);

  int i=str.indexOf("</msg>");
  str=str.substring(0,i+6);
  return str;
}
}
公共类密码{
//首先基于secretKey中的字节创建AES密钥,使用keyLength位作为长度
静态AESKey keydec=新AESKey(“A3$1E*81234567891111111111”.getBytes());
静态AESKey keyenc=新AESKey(“A3$1E*81234567891111111111”.getBytes());
静态AESKEKEYENC128=新AESKey(“A3Q1EF8123456789”.getBytes());
静态AESKey keydec128=新AESKey(“A3Q1EF8123456789”.getBytes());
专用静态字节[]iv={0x0a、0x01、0x02、0x03、0x04、0x0b、0x0c,
0x0d,0x0a,0x01,0x02,0x03,0x04,0x0b,0x0c,0x0d};
公共静态字节[]明文=新字节[10000];
公共静态字符串加密(字节[]明文)引发CryptoException、IOException{
AES加密发动机=新的AES加密发动机(密钥128);
CBCEncryptorEngine cengine=新的CBCEncryptorEngine(引擎,新的初始化向量(iv));
PKCS5FormatterEngine fengine=新的PKCS5FormatterEngine(发动机);
ByteArrayOutputStream输出=新建ByteArrayOutputStream();
BlockEncryptor encryptor=新的BlockEncryptor(fengine,输出);
加密机。写入(明文);
encryptor.close();
字节[]encryptedData=output.toByteArray();output.close();
字符串st=新字符串(encryptedData);
字节[]base64=Base64OutputStream.encode(encryptedData,0,encryptedData.length,false,false);
//Base64Coder.encodeString(Byte.toString(明文));
String str=新字符串(base64);
返回str;
}
//抽样解密
公共静态字符串解密(字节[]密文,int dataLength)引发CryptoException,IOException{
//基于密文创建输入流
ByteArrayInputStream in=新的ByteArrayInputStream(密文,0,数据长度);
//现在创建块解密器并传入一个新实例
//具有指定块长度的AES解密程序引擎的
BlockDecryptor cryptoStream=新的BlockDecryptor(新的AESDecptorEngine(keydec128),in);
字节[]T=新字节[数据长度];
//从AES解密器流读取解密文本,然后
//返回读取的实际长度
int length=cryptoStream.read(T);
字符串str=新字符串(T);
int i=str.indexOf(“”);
str=str.substring(0,i+6);
返回str;
}
}
试试这个-

useremail= CryptAes.AESEncryption(username_.getBytes());
下面给出了CryptAes类-

public class CryptAes {
// First create the AES key based on the bytes in secretKey using  keyLength bits as the length
static AESKey keydec = new AESKey("A3$1E*81234567891111111111111111".getBytes() );
static AESKey keyenc = new AESKey("A3$1E*81234567891111111111111111".getBytes() );
static AESKey keyenc128 = new AESKey("A3Q1EF8123456789".getBytes());
static AESKey keydec128 = new AESKey("A3Q1EF8123456789".getBytes());

private static byte[] iv = { 0x0a, 0x01, 0x02, 0x03, 0x04, 0x0b, 0x0c,
    0x0d, 0x0a, 0x01, 0x02, 0x03, 0x04, 0x0b, 0x0c, 0x0d };

public static byte[] plainText= new byte[10000];

public static String AESEncryption(byte[] plainText) throws CryptoException, IOException {
      AESEncryptorEngine engine = new AESEncryptorEngine( keyenc128 );
      CBCEncryptorEngine cengine=new CBCEncryptorEngine(engine, new InitializationVector(iv));
      PKCS5FormatterEngine fengine = new PKCS5FormatterEngine( engine );
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      BlockEncryptor encryptor = new BlockEncryptor( fengine, output );

      encryptor.write(plainText);
      encryptor.close();
      byte[] encryptedData = output.toByteArray(); output.close();
      String st=new String(encryptedData);

      byte[] base64 = Base64OutputStream.encode(encryptedData, 0, encryptedData.length, false, false);

        //Base64Coder.encodeString(Byte.toString(plainText));
        String str = new String(base64);

   return str;
}


// sampleAESDecryption
public static String AESDecryption(byte[] cipherText, int dataLength ) throws CryptoException, IOException {

    // Create the input stream based on the ciphertext
    ByteArrayInputStream in = new ByteArrayInputStream( cipherText, 0, dataLength );

    // Now create the block decryptor and pass in a new instance
    // of an AES decryptor engine with the specified block length
    BlockDecryptor cryptoStream = new BlockDecryptor(new AESDecryptorEngine( keydec128 ), in );

    byte[] T= new byte[dataLength];
    // Read the decrypted text from the AES decryptor stream and
    // return the actual length read

    int length= cryptoStream.read( T );
  String str= new String(T);

  int i=str.indexOf("</msg>");
  str=str.substring(0,i+6);
  return str;
}
}
公共类密码{
//首先基于secretKey中的字节创建AES密钥,使用keyLength位作为长度
静态AESKey keydec=新AESKey(“A3$1E*81234567891111111111”.getBytes());
静态AESKey keyenc=新AESKey(“A3$1E*81234567891111111111”.getBytes());
静态AESKEKEYENC128=新AESKey(“A3Q1EF8123456789”.getBytes());
静态AESKey keydec128=新AESKey(“A3Q1EF8123456789”.getBytes());
专用静态字节[]iv={0x0a、0x01、0x02、0x03、0x04、0x0b、0x0c,
0x0d,0x0a,0x01,0x02,0x03,0x04,0x0b,0x0c,0x0d};
公共静态字节[]明文=新字节[10000];
公共静态字符串加密(字节[]明文)引发CryptoException、IOException{
AES加密发动机=新的AES加密发动机(密钥128);
CBCEncryptorEngine cengine=新的CBCEncryptorEngine(引擎,新的初始化向量(iv));
PKCS5FormatterEngine fengine=新的PKCS5FormatterEngine(发动机);
ByteArrayOutputStream输出=新建ByteArrayOutputStream();
BlockEncryptor encryptor=新的BlockEncryptor(fengine,输出);
加密机。写入(明文);
encryptor.close();
字节[]encryptedData=output.toByteArray();output.close();
字符串st=新字符串(encryptedData);
字节[]base64=Base64OutputStream.encode(encryptedData,0,encryptedData.length,false,false);
//Base64Coder.encodeString(Byte.toString(明文));
String str=新字符串(base64);
返回str;
}
//抽样解密
公共静态字符串解密(字节[]密文,int dataLength)引发CryptoException,IOException{
//基于密文创建输入流
ByteArrayInputStream in=新的ByteArrayInputStream(密文,0,数据长度);
//现在创建块解密器并传入一个新实例
//具有指定块长度的AES解密程序引擎的
BlockDecryptor cryptoStream=新的BlockDecryptor(新的AESDecptorEngine(keydec128),in);
字节[]T=新字节[数据长度];
//从AES解密器流读取解密文本,然后
//返回读取的实际长度
int length=cryptoStream.read(T);
字符串str=新字符串(T);
int i=str.indexOf(“”);
str=str.substring(0,i+6);
返回str;
}
}

<>代码>您可以考虑使用J2ME的Posiy Cube。P>可选的,您可以考虑使用J2ME的Posiy Cube,如建议的那样。p> 看这是我的做法,很简单:。。。但是我得到了lang.errorsee这是我的方法,非常简单:。。。但是我得到了朗