私はJavaとJSの両方でnewbeeで、自分の既存のJSコードで暗号化解除する必要があるjavaでパスワードを暗号化しようとしています。 (私のJSを変更したくない!)Crypto JSを使用してJavaScriptでJavaおよびDycryptで暗号化することはできません。
私はそれがKEYとIVとは何かを持っていると私は全く気づかない。
** Javaプログラム**
public class Helper {
public Cipher dcipher, ecipher;
// Responsible for setting, initializing this object's encrypter and
// decrypter Chipher instances
public Helper(String passPhrase) {
// 8-bytes Salt
byte[] salt = {(byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32, (byte) 0x56, (byte) 0x34, (byte) 0xE3, (byte) 0x03};
// Iteration count
int iterationCount = 19;
try {
// Generate a temporary key. In practice, you would save this key
// Encrypting with DES Using a Pass Phrase
KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), salt, iterationCount);
SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
ecipher = Cipher.getInstance(key.getAlgorithm());
// Prepare the parameters to the cipthers
AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);
ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
} catch (InvalidAlgorithmParameterException e) {
System.out.println("EXCEPTION: InvalidAlgorithmParameterException");
} catch (InvalidKeySpecException e) {
System.out.println("EXCEPTION: InvalidKeySpecException");
} catch (NoSuchPaddingException e) {
System.out.println("EXCEPTION: NoSuchPaddingException");
} catch (NoSuchAlgorithmException e) {
System.out.println("EXCEPTION: NoSuchAlgorithmException");
} catch (InvalidKeyException e) {
System.out.println("EXCEPTION: InvalidKeyException");
}
}
// Encrpt Password
@SuppressWarnings("unused")
public String encrypt(String str) {
try {
// Encode the string into bytes using utf-8
byte[] utf8 = str.getBytes("UTF8");
System.out.println("\n UTF8 : " + utf8);
// Encrypt
byte[] enc = ecipher.doFinal(utf8);
System.out.println("\n enc: " + enc);
// Encode bytes to base64 to get a string
return new sun.misc.BASE64Encoder().encode(enc);
} catch (BadPaddingException e) {
} catch (IllegalBlockSizeException e) {
} catch (UnsupportedEncodingException e) {
}
return null;
}
public static void main(String[] args) {
try {
Helper encrypter = new Helper("");
System.out.print("Enter a password : ");
String password = input.nextLine();
String encrypted = encrypter.encrypt(password);
System.out.println("encrypted String:" + encrypted);
} catch (Exception e) {
}
}
}キー暗号化しなければならないプログラム上
- 次によって復号化されますJS:
var encryptedpassword=this.bodyParams.password;
var bytes = CryptoJS.AES.decrypt(encryptedpassword.toString(), accKey);
var newpassword = bytes.toString(CryptoJS.enc.Utf8);
accKey = "Nqnzu3RhCJ1h8ql5fdKOaKUAbsuURze ********* _
9/10これらの暗号の問題は、JSのユニコード文字列と他の人の非ユニコード文字列によって引き起こされます。 – dandavis
何をするべきか提案できますか?私は両方のもので新しいので、ここでほとんど助けが必要です。 –
私はあなたが単にパスワードを解読するのではなく、同じ鍵(または塩)を利用して入ってくるパスワードを暗号化し、2つの暗号を比較することを提案したいと思います。それを提供した人とパスワードを残してください。 :D – DevilsHnd