Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
public void crypt(String deinString) throws Exception
{
byte[] input = deinString.getBytes();
SecretKeySpec key = new SecretKeySpec("passwort".getBytes(), "DES");
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS7Padding");
System.out.println("input : " + new String(input));
// encryption
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] cipherText = new byte[cipher.getOutputSize(input.length)];
int ctLength = cipher.update(input, 0, input.length, cipherText, 0);
ctLength += cipher.doFinal(cipherText, ctLength);
System.out.println("cipher: " + new String(cipherText) + " bytes: " + ctLength);
// decryption
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] plainText = new byte[cipher.getOutputSize(ctLength)];
int ptLength = cipher.update(cipherText, 0, ctLength, plainText, 0);
ptLength += cipher.doFinal(plainText, ptLength);
System.out.println("plain : " + new String(plainText) + " bytes: " + ptLength);
}
public String encrypt(String str, String code)
{
byte[] ptBytes = str.getBytes();
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new DESEngine()),
new PKCS7Padding());
CipherParameters cp = new KeyParameter(code.getBytes());
ParametersWithIV parametersWithIV = new ParametersWithIV(cp, code.getBytes());
cipher.init(true,parametersWithIV);
byte[] rv = new byte[cipher.getOutputSize(ptBytes.length)];
int oLen = cipher.processBytes(ptBytes, 0, ptBytes.length, rv, 0);
try
{
cipher.doFinal(rv, oLen);
}
catch (CryptoException ce)
{
ce.printStackTrace();
}
System.out.println(new String(rv));
return new String(Base64.encode(rv));
}
// entschluesseln
public String decrypt(String str, String code)
{
byte[] cipherText = Base64.decode(str.getBytes());
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new DESEngine()),
new PKCS7Padding());
CipherParameters cp = new KeyParameter(code.getBytes());
ParametersWithIV parametersWithIV = new ParametersWithIV(cp, code.getBytes());
cipher.init(false,parametersWithIV);
byte[] rv = new byte[cipher.getOutputSize(cipherText.length)];
int oLen = cipher.processBytes(cipherText, 0, cipherText.length, rv, 0);
try
{
cipher.doFinal(rv, oLen);
}
catch (CryptoException ce)
{
ce.printStackTrace();
}
return new String(rv).trim();
}