我正在开发移动产品。我们正在使用xml document中的数据。为了保证我们的数据安全,我们需要一个加密算法(但我们不希望现有算法导入)
你能给我一些步骤来加密数据吗?(如果代码示例是最受欢迎的)。
发布于 2013-07-23 09:10:45
为了更安全,你必须使用你自己的秘密钥匙。尝试使用以下代码
KeyStore ks = KeyStore.getInstance();
// get the names of all keys created by our app
String[] keyNames = ks.saw("");
// store a symmetric key in the keystore
SecretKey key = Crypto.generateKey();
boolean success = ks.put("secretKey1", key.getEncoded());
// check if operation succeeded and get error code if not
if (!success) {
int errorCode = ks.getLastError();
throw new RuntimeException("Keystore error: " + errorCode);
}
// get a key from the keystore
byte[] keyBytes = ks.get("secretKey1");
SecretKey key = new SecretKeySpec(keyBytes, "AES");
// delete a key
boolean success = ks.delete("secretKey1");发布于 2013-07-23 09:11:50
如果您想开发自己的加密方案,请准备开始一个研究项目。您可以使用任何标准加密算法,如AES/DES等,私钥足够长且难以破解。
发布于 2013-07-23 09:05:38
public string PassEncrypt(string Password)
{
// Encrypting the password entered by User
// ======================================================
MD5 md5 = new MD5CryptoServiceProvider();
md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(Password));
byte[] result = md5.Hash;
StringBuilder strBuilder = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
strBuilder.Append(result[i].ToString("x2"));
}
return strBuilder.ToString();
// ======================================================
}或
您可以参考以下链接:
developer.motorala.com
android片段
java-tips.org
https://stackoverflow.com/questions/17805763
复制相似问题