gcssloop / encrypt Goto Github PK
View Code? Open in Web Editor NEW[暂停维护]Android 加密解密工具包。
License: Apache License 2.0
[暂停维护]Android 加密解密工具包。
License: Apache License 2.0
自己在公司跟php调通了但是ios不通,如果有的话请发我一份。[email protected],感谢
https://android-developers.googleblog.com/2018/03/cryptography-changes-in-android-p.html
希望AES加密能够兼容到Android P。。
- android的rsa加密方式是--------RSA/ECB/NoPadding或者RSA/None/NoPadding
- 标准jdk的rsa加密方式是-------- RSA/ECB/PKCS1Padding或者RSA/None/PKCS1Padding
/*加密方式,android的*/
public static final String mAlgorithm= "RSA/ECB/NoPadding";
public static final String mAlgorithm= "RSA/None/NoPadding";
/*加密方式,标准jdk的*/
public static final String mAlgorithm= "RSA/ECB/PKCS1Padding";
public static final String mAlgorithm= "RSA/None/PKCS1Padding";
Cipher cp = Cipher.getInstance("RSA/ECB/PKCS1Padding");
Cipher cp = Cipher.getInstance("RSA/None/PKCS1Padding");
所以能否配置为可配置的算法模式填充?
是需要配置什么吗?我现在加密出来的密文无法在其他地方成功解密。代码如下:
public static String aes(String content, String password, @AESType int type) {
try {
KeyGenerator generator = KeyGenerator.getInstance("AES");
SecureRandom secureRandom;
if (android.os.Build.VERSION.SDK_INT >= 24) {
secureRandom = SecureRandom.getInstance(SHA1PRNG, new CryptoProvider());
} else if (android.os.Build.VERSION.SDK_INT >= 17) {
secureRandom = SecureRandom.getInstance(SHA1PRNG, "Crypto");
} else {
secureRandom = SecureRandom.getInstance(SHA1PRNG);
}
secureRandom.setSeed(password.getBytes());
generator.init(128, secureRandom);
SecretKey secretKey = generator.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
@SuppressLint("GetInstance") Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
cipher.init(type, key);
if (type == Cipher.ENCRYPT_MODE) {
byte[] byteContent = content.getBytes("UTF-8");
return parseByte2HexStr(cipher.doFinal(byteContent));
} else {
byte[] byteContent = parseHexStr2Byte(content);
byte[] doFinal = cipher.doFinal(byteContent);
return new String(doFinal);
}
} catch (NoSuchAlgorithmException | BadPaddingException | IllegalBlockSizeException |
InvalidKeyException | NoSuchPaddingException |
NoSuchProviderException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
解密之后文件会损坏 请问有什么办法吗
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.