【问题标题】:To Encrypt the IMEI number加密 IMEI 号码
【发布时间】:2012-05-28 15:06:48
【问题描述】:

我有找到设备IMEI号码的代码,但现在我想加密那个格式,我该如何加密?

【问题讨论】:

    标签: android imei


    【解决方案1】:

    您可以使用以下函数:

    private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
            byte[] encrypted = cipher.doFinal(clear);
            return encrypted;
        }
    
        private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec);
            byte[] decrypted = cipher.doFinal(encrypted);
            return decrypted;
        }
    

    然后像这样调用它们:

    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
    bm.compress(Bitmap.CompressFormat.PNG, 100, baos); // bm is the bitmap object   
    byte[] b = baos.toByteArray();  
    
    byte[] keyStart = "this is a key".getBytes();
    KeyGenerator kgen = KeyGenerator.getInstance("AES");
    SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
    sr.setSeed(keyStart);
    kgen.init(128, sr); // 192 and 256 bits may not be available
    SecretKey skey = kgen.generateKey();
    byte[] key = skey.getEncoded();    
    
    // encrypt
    byte[] encryptedData = encrypt(key,b);
    // decrypt
    byte[] decryptedData = decrypt(key,encryptedData);
    

    参考来自:android encryption/decryption with AES

    【讨论】:

    • 那里有抄袭?请将功劳归功于原始答案;)
    【解决方案2】:

    这里给出使用 Cipher 对字符串进行加密和解密的示例

    http://www.androidsnippets.com/encryptdecrypt-strings
    

    【讨论】:

      【解决方案3】:

      如果您尝试在设备本身上加密号码,这是不可能的。

      如果你想用你的代码加密你得到的号码,有很多方法可以做到这一点,试试看这个代码 sn-p:http://www.androidsnippets.com/encryptdecrypt-strings

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-01-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-19
        • 2014-10-03
        • 2011-01-28
        相关资源
        最近更新 更多