提交 3309e088 authored 作者: Thomas Mueller's avatar Thomas Mueller

New experimental pseudo-encryption algorithm "FOG".

上级 560d0380
...@@ -18,7 +18,16 @@ Change Log ...@@ -18,7 +18,16 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Password hash: in addition to connecting with the plain text password, <ul><li>-
</li></ul>
<h2>Version 1.2.141 (2010-08-22)</h2>
<ul><li>New experimental pseudo-encryption algorithm "FOG".
It makes the data appear to be encrypted. This algorithm is cryptographically extremely weak,
and should only be used to hide data from reading the plain text using a text editor.
Please let us know if you think this is useful or not.
</li><li>Documentation: the grammar and function documentation can now be easier translated.
</li><li>Password hash: in addition to connecting with the plain text password,
H2 now supports connecting with the password hash. H2 now supports connecting with the password hash.
Like this you don't have to store plain text passwords in config files. Like this you don't have to store plain text passwords in config files.
For details, see the documentation at Advanced / Password Hash. For details, see the documentation at Advanced / Password Hash.
......
...@@ -244,7 +244,7 @@ public class AES implements BlockCipher { ...@@ -244,7 +244,7 @@ public class AES implements BlockCipher {
} }
public int getKeyLength() { public int getKeyLength() {
return 4 * 4; return 16;
} }
} }
...@@ -50,4 +50,5 @@ public interface BlockCipher { ...@@ -50,4 +50,5 @@ public interface BlockCipher {
* @return the length of the key * @return the length of the key
*/ */
int getKeyLength(); int getKeyLength();
} }
...@@ -63,6 +63,8 @@ public class CipherFactory { ...@@ -63,6 +63,8 @@ public class CipherFactory {
return new XTEA(); return new XTEA();
} else if ("AES".equalsIgnoreCase(algorithm)) { } else if ("AES".equalsIgnoreCase(algorithm)) {
return new AES(); return new AES();
} else if ("FOG".equalsIgnoreCase(algorithm)) {
return new Fog();
} }
throw DbException.get(ErrorCode.UNSUPPORTED_CIPHER, algorithm); throw DbException.get(ErrorCode.UNSUPPORTED_CIPHER, algorithm);
} }
......
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.security;
import org.h2.util.Utils;
/**
* A pseudo-encryption algorithm that makes the data appear to be
* encrypted. This algorithm is cryptographically extremely weak, and should
* only be used to hide data from reading the plain text using a text editor.
*/
public class Fog implements BlockCipher {
private int key;
public void encrypt(byte[] bytes, int off, int len) {
for (int i = off; i < off + len; i += 16) {
encryptBlock(bytes, bytes, i);
}
}
public void decrypt(byte[] bytes, int off, int len) {
for (int i = off; i < off + len; i += 16) {
decryptBlock(bytes, bytes, i);
}
}
private void encryptBlock(byte[] in, byte[] out, int off) {
int x0 = (in[off] << 24) | ((in[off+1] & 255) << 16) | ((in[off+2] & 255) << 8) | (in[off+3] & 255);
int x1 = (in[off+4] << 24) | ((in[off+5] & 255) << 16) | ((in[off+6] & 255) << 8) | (in[off+7] & 255);
int x2 = (in[off+8] << 24) | ((in[off+9] & 255) << 16) | ((in[off+10] & 255) << 8) | (in[off+11] & 255);
int x3 = (in[off+12] << 24) | ((in[off+13] & 255) << 16) | ((in[off+14] & 255) << 8) | (in[off+15] & 255);
int k = key;
int s = x1 & 31;
x0 ^= k;
x0 = (x0 << s) | (x0 >>> (32 - s));
x2 ^= k;
x2 = (x2 << s) | (x2 >>> (32 - s));
s = x0 & 31;
x1 ^= k;
x1 = (x1 << s) | (x1 >>> (32 - s));
x3 ^= k;
x3 = (x3 << s) | (x3 >>> (32 - s));
out[off] = (byte) (x0 >> 24); out[off+1] = (byte) (x0 >> 16); out[off+2] = (byte) (x0 >> 8); out[off+3] = (byte) x0;
out[off+4] = (byte) (x1 >> 24); out[off+5] = (byte) (x1 >> 16); out[off+6] = (byte) (x1 >> 8); out[off+7] = (byte) x1;
out[off+8] = (byte) (x2 >> 24); out[off+9] = (byte) (x2 >> 16); out[off+10] = (byte) (x2 >> 8); out[off+11] = (byte) x2;
out[off+12] = (byte) (x3 >> 24); out[off+13] = (byte) (x3 >> 16); out[off+14] = (byte) (x3 >> 8); out[off+15] = (byte) x3;
}
private void decryptBlock(byte[] in, byte[] out, int off) {
int x0 = (in[off] << 24) | ((in[off+1] & 255) << 16) | ((in[off+2] & 255) << 8) | (in[off+3] & 255);
int x1 = (in[off+4] << 24) | ((in[off+5] & 255) << 16) | ((in[off+6] & 255) << 8) | (in[off+7] & 255);
int x2 = (in[off+8] << 24) | ((in[off+9] & 255) << 16) | ((in[off+10] & 255) << 8) | (in[off+11] & 255);
int x3 = (in[off+12] << 24) | ((in[off+13] & 255) << 16) | ((in[off+14] & 255) << 8) | (in[off+15] & 255);
int k = key;
int s = 32 - (x0 & 31);
x1 = (x1 << s) | (x1 >>> (32 - s));
x1 ^= k;
x3 = (x3 << s) | (x3 >>> (32 - s));
x3 ^= k;
s = 32 - (x1 & 31);
x0 = (x0 << s) | (x0 >>> (32 - s));
x0 ^= k;
x2 = (x2 << s) | (x2 >>> (32 - s));
x2 ^= k;
out[off] = (byte) (x0 >> 24); out[off+1] = (byte) (x0 >> 16); out[off+2] = (byte) (x0 >> 8); out[off+3] = (byte) x0;
out[off+4] = (byte) (x1 >> 24); out[off+5] = (byte) (x1 >> 16); out[off+6] = (byte) (x1 >> 8); out[off+7] = (byte) x1;
out[off+8] = (byte) (x2 >> 24); out[off+9] = (byte) (x2 >> 16); out[off+10] = (byte) (x2 >> 8); out[off+11] = (byte) x2;
out[off+12] = (byte) (x3 >> 24); out[off+13] = (byte) (x3 >> 16); out[off+14] = (byte) (x3 >> 8); out[off+15] = (byte) x3;
}
public int getKeyLength() {
return 16;
}
public void setKey(byte[] key) {
this.key = (int) Utils.readLong(key, 0);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论