我正在使用此代码段来加密/解密我的应用程序数据库中的数据:
http://www.androidsnippets.com/encryptdecrypt-strings
似乎javax.crypto.KeyGenerator.generateKey()操作在Android 2.3.3操作系统中的工作方式与其他(以前的?)版本不同.当然,这会给我的用户带来一个主要问题,当他们将设备从2.2升级到2.3.3并且应用程序开始抛出解密数据库的错误.
这是一个已知的问题?我是否错误地使用了加密库?任何人都有任何关于如何解决这个问题的建议,以便2.2中加密的数据能够在2.3.3中解密?
我构建了一个测试应用程序,通过加密功能提供值.当我在2.2 AVD上运行它时,我得到一个结果.当我在2.3.3 AVD上运行时,我得到了不同的结果.
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class main extends Activity {
TextView tvOutput;
static String out;
String TEST_STRING = "abcdefghijklmnopqrstuvwxyz";
String PASSKEY = "ThePasswordIsPassord";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tvOutput = (TextView) findViewById(R.id.tvOutput);
}
@Override
public void onResume() {
super.onResume();
out = "";
runTest();
tvOutput.setText(out);
}
private void runTest() …Run Code Online (Sandbox Code Playgroud) GPG总是在结果返回2.我的代码如下
$cmd = "/usr/bin/gpg -a --recipient $to -e -o $outfile $infile";
outfile是加密数据将被写入的文件,infile是未加密的数据.
我不知道为什么会这样.任何人都可以告诉我有什么问题.谢谢.
几个小时以来,我一直在寻找将字符串加密到URL的完美方法.这是我找到的方法
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web;
public class SimplerAES
{
private static byte[] key = { 123, 217, 19, 11, 24, 26, 85, 45, 114, 184, 27, 162, 37, 112, 222, 209, 241, 24, 175, 144, 173, 53, 196, 29, 24, 26, 17, 218, 131, 236, 53, 209 };
private static byte[] vector = { 146, 64, 191, 111, 23, 3, 113, 119, 231, 121, 221, 112, 79, 32, 114, 156 };
private ICryptoTransform …Run Code Online (Sandbox Code Playgroud) 我有一个听众倾听连接变化,特别是从GSM到WIFI.现在我想记录用户连接的WIFI,尤其是WIFI的加密类型(无,WEP,WPA,WPA2,...).
听众工作得很好,但我找不到任何方法来获得当前的Wifi加密类型.
谢谢你的帮助.
我需要传输xml文件,并且需要加密它们.我发现一些例子认为我很接近,但是当我解密文件时,我最终会遇到尾随垃圾字符.有一些关于这个的帖子,但我没有看到任何将完全有帮助.这是加密和解密代码.
private void EncryptFile(string inputFile, string outputFile, string key) {
try {
byte[] keyBytes;
keyBytes = Encoding.Unicode.GetBytes(key);
Rfc2898DeriveBytes derivedKey = new Rfc2898DeriveBytes(key, keyBytes);
RijndaelManaged rijndaelCSP = new RijndaelManaged();
rijndaelCSP.Key = derivedKey.GetBytes(rijndaelCSP.KeySize / 8);
rijndaelCSP.IV = derivedKey.GetBytes(rijndaelCSP.BlockSize / 8);
ICryptoTransform encryptor = rijndaelCSP.CreateEncryptor();
FileStream inputFileStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
byte[] inputFileData = new byte[(int)inputFileStream.Length];
inputFileStream.Read(inputFileData, 0, (int)inputFileStream.Length);
FileStream outputFileStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
CryptoStream encryptStream = new CryptoStream(outputFileStream, encryptor, CryptoStreamMode.Write);
encryptStream.Write(inputFileData, 0, (int)inputFileStream.Length);
encryptStream.FlushFinalBlock();
rijndaelCSP.Clear();
encryptStream.Close();
inputFileStream.Close();
outputFileStream.Close();
} …Run Code Online (Sandbox Code Playgroud) 这可能是以前以多种形式提出过来的问题,但是我还没有看到它问过这个问题,我想对如何继续提出一些意见.
我正在开发一个应用程序,它需要将凭据存储到设备上的第三方Web服务.我希望加密这些凭据,但我也不希望将种子存储在设备上的代码/中以防止可能的劫持.该应用程序还支持使用Googles云备份功能进行备份,进一步需要加密.
我的想法是,如果我能找到一个唯一的标识符,那可以用作种子.有一些奇怪的要求使这很困难.
我明白这个值显然可以被其他应用程序检索,这就是为什么我打算哈希它,进一步播种应用程序UID以及<你的建议在这里>.
如果有人觉得这些要求不切实际,我也想听听.
特别是鉴于最近的黑客马拉松,我希望能够至少说"如果有人可以妥协,那么手机上没有任何东西是安全的".
所以...我阅读了jellybean更新说明并看到"Jelly Bean为付费应用程序引入了应用程序加密."
据我所知,当有人将其apk移动到另一台设备时,此服务应该使应用程序无法使用.
但是非豆豆机器人怎么样?如果有人将apk从软件设备移动到ICS设备,这个加密功能是否还能正常工作?
我正在寻找两个适合的代码片段来编码python的一些文本,这将在PHP中解码.我正在寻找"简单"和兼容的东西,我自己没有太多的加密经验.
如果有人能给出一个很棒的工作示例!
我一直在尝试使用Java加密PDF.到目前为止,我可以成功加密其他文件类型(.txt,.png等).当我使用PDF时,它会在我解密时打破信息.
这就是我用它来加密它:
public byte[] cryptograph(Key key, byte[] content){
Cipher cipher;
byte[] cryptograph = null;
try {
cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key);
cryptograph = cipher.doFinal(content);
} catch (Exception e) {
e.printStackTrace();
}
return cryptograph;
}
Run Code Online (Sandbox Code Playgroud)
这要解密它:
public byte[] decrypt(Key key,byte[] textCryp){
Cipher cipher;
byte[] decrypted = null;
try {
cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, key);
decrypted = cipher.doFinal(textCryp);
} catch (Exception e) {
e.printStackTrace();
}
return decrypted;
}
Run Code Online (Sandbox Code Playgroud)
更新:
这是我用来读取文件的内容:
public byte[] getFile(){
byte[] content = null;
try {
InputStream is = …Run Code Online (Sandbox Code Playgroud) 我的cocos2d游戏使用CCCrypt()加密保存数据.我使用mac地址作为加密密钥.在IOS5中加密的保存文件无法使用IOS6中的相同mac地址进行解密.这意味着更新游戏的用户将丢失所有数据!
有没有办法解密旧文件?
这是代码:
@implementation NSData (AESAdditions)
- (NSData*)AES256EncryptWithKey:(NSString*)key {
// 'key' should be 32 bytes for AES256, will be null-padded otherwise
char keyPtr[kCCKeySizeAES256 + 1]; // room for terminator (unused)
bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding)
// fetch key data
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
NSUInteger dataLength = [self length];
//See the doc: For block ciphers, the output size will always be less than or
//equal to the input size plus the size of one block.
//That's why we …Run Code Online (Sandbox Code Playgroud) encryption ×10
android ×4
c# ×2
java ×2
php ×2
connection ×1
cryptography ×1
gnupg ×1
ios ×1
ios5 ×1
ios6 ×1
javax.crypto ×1
objective-c ×1
pdf ×1
python ×1
wifi ×1