【发布时间】:2019-12-14 18:03:04
【问题描述】:
我很麻烦,如何在ionic4中使用crypto js进行加密/解密?
我用java写了加密解密的代码
public static String encrypt(String str)
{
String encryptedString = str;
try {
byte[] utf8 = str.getBytes("UTF8");
byte[] enc = encryptor.doFinal(utf8);
encryptedString = Base64.encodeBase64URLSafeString(enc);
} catch (Exception e) {
e.printStackTrace();
}
return encryptedString;
}
用于解密
public static String decrypt(String str)
{
String decryptedString = "";
try {
byte[] dec = Base64.decodeBase64(str);
byte[] utf8 = decryptor.doFinal(dec);
decryptedString = new String(utf8, "UTF8");
} catch (Exception e) {
e.printStackTrace();
}
return decryptedString;
}
密钥生成
public static void genKeyPair(int i) {
try {
// generates DES key from string //
key = new SecretKeySpec(Skey.getBytes(), "DES");
// initialize the cipher with key //
encryptor = Cipher.getInstance("DES");
decryptor = Cipher.getInstance("DES");
encryptor.init(Cipher.ENCRYPT_MODE, key);
decryptor.init(Cipher.DECRYPT_MODE, key);
System.err.println(java.util.Base64.getEncoder().encodeToString(key.getEncoded()));
} catch (Exception e) {
e.printStackTrace();
}
}
我想在ionic4中写同样的东西,请帮助我。我是ionic4(混合应用程序)的新手
【问题讨论】:
标签: angular ionic-framework encryption cryptojs caesar-cipher