package ssi.staaar.messages;
import java.security.PrivateKey;
import java.security.PublicKey;
import android.util.Log;
import ssi.staaar.ciphers.SHA1Digester;
import ssi.staaar.ciphers.SymCipher;
import encoders.Base64;
public class RegMessage extends LowLevelMessage {
private String username;
private String email;
private String password;
private PublicKey pubKey;
private PrivateKey privKey;
private String cryptedPriv;
private long timestamp;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public PublicKey getPubKey() {
return pubKey;
}
public void setPubKey(PublicKey pubKey) {
this.pubKey = pubKey;
}
public PrivateKey getPrivKey() {
return privKey;
}
public void setPrivKey(PrivateKey privKey) {
this.privKey = privKey;
}
public String getCryptedPriv() {
return cryptedPriv;
}
public void setCryptedPriv(String cryptedPriv) {
this.cryptedPriv = cryptedPriv;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long l) {
this.timestamp = l;
}
public String toString(){
SymCipher sym = new SymCipher();
String symKey=String.format("%1$-" + 16 + "s", password);
//Log.d("REC", "symkey " + symKey.length());
//symKey.replace(' ', '#');
sym.setPasswordAsKey(password);
//sym.setKey("aaaaaaaaaaaaaaaa");
String chiave = new String((Base64.encode(pubKey.getEncoded())));
String priv = "";
try {
priv = sym.crypt(new String(Base64.encode(privKey.getEncoded())));
Log.d("REC","la chiave privata :" + priv);
} catch (Exception e) {
e.printStackTrace();
}
return username + "!-!" + email + "!-!" + SHA1Digester.digestString(password) + "!-!" + timestamp + "!-!"+ priv + "\r\n" + chiave.length() + "\r\n" + chiave;
}
}
|