Page MenuHomec4science

FragmentPartialEncoded.java
No OneTemporary

File Metadata

Created
Wed, Nov 13, 09:48

FragmentPartialEncoded.java

package crypto.elgamal.fragment;
import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECPoint;
import crypto.elgamal.ECElGamal;
public class FragmentPartialEncoded extends FragmentEncoded {
private byte[] encodedT;
private int partNumber;
public FragmentPartialEncoded(byte[] encodedR, byte[] encodedS, byte[] encodedT,
int partNumber) {
super(encodedR, encodedS);
this.encodedT = encodedT;
this.partNumber = partNumber;
}
public FragmentPartialEncoded(String base64R, String base64S, String base64T, int partNumber) {
super(base64R, base64S);
// check sanity
if (!Base64.isBase64(base64T)) {
throw new IllegalArgumentException("Unvalid base64 format!");
}
this.encodedT = Base64.decodeBase64(base64T);
this.partNumber = partNumber;
}
public FragmentPartialEncoded(FragmentPartial partial) {
super(partial);
encodedT = partial.getT().getEncoded();
partNumber = partial.getPartNumber();
}
public byte[] getEncodedT() {
return encodedT;
}
public int getPartNumber() {
return partNumber;
}
public FragmentPartial decodeFragment(ECCurve curve) {
FragmentEncrypted encrypted = super.decodeFragment(curve);
ECPoint T = curve.decodePoint(encodedT);
return new FragmentPartial(partNumber, encrypted, T);
}
public FragmentPartial decodeFragment(ECElGamal ecceg) {
return decodeFragment(ecceg.getCurve());
}
public String encodeBase64(String separator) {
StringBuilder builder = new StringBuilder();
builder.append(Integer.toString(partNumber));
builder.append(separator);
builder.append(Base64.encodeBase64String(super.getEncodedR()));
builder.append(separator);
builder.append(Base64.encodeBase64String(super.getEncodedS()));
builder.append(separator);
builder.append(Base64.encodeBase64String(encodedT));
return builder.toString();
}
}

Event Timeline