リンクからコードへの文字列暗号化クラスを実装しようとしています
Android プロジェクトに入れようとすると、次のエラーが表示されます。
説明 リソース パス 場所 タイプ インポートの太陽を解決できません SimpleProtector.java /EncryptedSMS/src/com/nsaers/encryptedsms 行 7 Java 問題 BASE64Decoder をタイプに解決できませんJava の問題 BASE64Encoder を型に解決できない SimpleProtector.java /EncryptedSMS/src/com/nsaers/encryptedsms 行 21 Java の問題
何か案は?
クラスの私のコードは次のとおりです。
package com.nsaers.encryptedsms;
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class SimpleProtector {
private static final String ALGORITHM = "AES";
private static final byte[] keyValue = new byte[] { 'T', 'h', 'i', 's',
'I', 's', 'A', 'S', 'e', 'c', 'r', 'e', 't', 'K', 'e', 'y' };
public static String encrypt(String valueToEnc) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGORITHM);
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encValue = c.doFinal(valueToEnc.getBytes());
String encryptedValue = new BASE64Encoder().encode(encValue);
return encryptedValue;
}
public static String decrypt(String encryptedValue) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGORITHM);
c.init(Cipher.DECRYPT_MODE, key);
byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedValue);
byte[] decValue = c.doFinal(decordedValue);
String decryptedValue = new String(decValue);
return decryptedValue;
}
private static Key generateKey() throws Exception {
Key key = new SecretKeySpec(keyValue, ALGORITHM);
// SecretKeyFactory keyFactory =
// SecretKeyFactory.getInstance(ALGORITHM);
// key = keyFactory.generateSecret(new DESKeySpec(keyValue));
return key;
}
}