use of co.krypt.krypton.pgp.codesign.UnsignedBinaryDocument in project krypton-android by kryptco.
the class PGPCodesignTest method dataSigning_succeeds.
@Test
public void dataSigning_succeeds() throws Exception {
final byte[] data = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
SSHKeyPairI kp1 = KeyManager.loadOrGenerateKeyPair(InstrumentationRegistry.getTargetContext(), KeyType.RSA, "test");
PGPPublicKey pubkey = new PGPPublicKey(kp1, Collections.singletonList(new UserID("Kevin King", "kevin@krypt.co")));
UnsignedBinaryDocument unsigned = new UnsignedBinaryDocument(data, kp1, HashAlgorithm.SHA512);
SignedSignatureAttributes sig = unsigned.sign(kp1.pgpSign(HashAlgorithm.SHA512, SignableUtils.signableBytes(unsigned)));
byte[] serializedSig = sig.serializedBytes();
SignedSignatureAttributes parsedSig = SignedSignatureAttributes.parse(new DataInputStream(new ByteArrayInputStream(serializedSig)));
Assert.assertTrue(parsedSig.attributes.attributes.hashAlgorithm == HashAlgorithm.SHA512);
Assert.assertTrue(parsedSig.attributes.attributes.pkAlgorithm == PublicKeyAlgorithm.RSA_SIGN_ONLY);
Assert.assertTrue(parsedSig.attributes.attributes.type == SignatureType.BINARY);
Assert.assertFalse(parsedSig.attributes.attributes.unhashedSubpackets.issuer.header.type.critical);
}
use of co.krypt.krypton.pgp.codesign.UnsignedBinaryDocument in project krypton-android by kryptco.
the class PGPSignatureTest method signedBinaryDocumentHashPrefix_matches.
@Test
public void signedBinaryDocumentHashPrefix_matches() throws Exception {
byte[] signatureBytes = AsciiArmor.parse(testSig1).data;
SignedSignatureAttributes sig = SignedSignatureAttributes.parse(new DataInputStream(new ByteArrayInputStream(signatureBytes)));
UnsignedBinaryDocument doc = new UnsignedBinaryDocument(signedData1.getBytes("UTF-8"), sig.attributes.attributes);
Assert.assertTrue(SignableUtils.hashPrefix(sig.attributes.attributes.hashAlgorithm, doc) == sig.attributes.hashPrefix);
ByteArrayOutputStream reserialized = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(reserialized);
sig.serialize(out);
out.close();
Assert.assertTrue(Arrays.equals(reserialized.toByteArray(), signatureBytes));
}
Aggregations