@Deprecated public static RSASignature decodeSSHRSASignature(byte[] sig) throws IOException { TypesReader tr = new TypesReader(sig); String sig_format = tr.readString(); if (!sig_format.equals("ssh-rsa")) throw new IOException("Peer sent wrong signature format"); /* S is NOT an MPINT. "The value for 'rsa_signature_blob' is encoded as a string * containing s (which is an integer, without lengths or padding, unsigned and in * network byte order)." See also below. */ byte[] s = tr.readByteString(); if (s.length == 0) throw new IOException("Error in RSA signature, S is empty."); if (log.isEnabled()) { log.log(80, "Decoding ssh-rsa signature string (length: " + s.length + ")"); } if (tr.remain() != 0) throw new IOException("Padding in RSA signature!"); return new RSASignature(new BigInteger(1, s)); }
@Deprecated public static byte[] encodeSSHRSASignature(RSASignature sig) throws IOException { TypesWriter tw = new TypesWriter(); tw.writeString("ssh-rsa"); /* S is NOT an MPINT. "The value for 'rsa_signature_blob' is encoded as a string * containing s (which is an integer, without lengths or padding, unsigned and in * network byte order)." */ byte[] s = sig.getS().toByteArray(); /* Remove first zero sign byte, if present */ if ((s.length > 1) && (s[0] == 0x00)) tw.writeString(s, 1, s.length - 1); else tw.writeString(s, 0, s.length); return tw.getBytes(); }
public static byte[] encodeSSHRSASignature(RSASignature sig) throws IOException { TypesWriter tw = new TypesWriter(); tw.writeString("ssh-rsa"); /* S is NOT an MPINT. "The value for 'rsa_signature_blob' is encoded as a string * containing s (which is an integer, without lengths or padding, unsigned and in * network byte order)." */ byte[] s = sig.getS().toByteArray(); /* Remove first zero sign byte, if present */ if ((s.length > 1) && (s[0] == 0x00)) tw.writeString(s, 1, s.length - 1); else tw.writeString(s, 0, s.length); return tw.getBytes(); }
public static RSASignature decodeSSHRSASignature(byte[] sig) throws IOException { TypesReader tr = new TypesReader(sig); String sig_format = tr.readString(); if (sig_format.equals("ssh-rsa") == false) throw new IOException("Peer sent wrong signature format"); /* S is NOT an MPINT. "The value for 'rsa_signature_blob' is encoded as a string * containing s (which is an integer, without lengths or padding, unsigned and in * network byte order)." See also below. */ byte[] s = tr.readByteString(); if (s.length == 0) throw new IOException("Error in RSA signature, S is empty."); if (log.isEnabled()) { log.log(80, "Decoding ssh-rsa signature string (length: " + s.length + ")"); } if (tr.remain() != 0) throw new IOException("Padding in RSA signature!"); return new RSASignature(new BigInteger(1, s)); }
public static byte[] encodeSSHRSASignature(RSASignature sig) throws IOException { TypesWriter tw = new TypesWriter(); tw.writeString("ssh-rsa"); /* S is NOT an MPINT. "The value for 'rsa_signature_blob' is encoded as a string * containing s (which is an integer, without lengths or padding, unsigned and in * network byte order)." */ byte[] s = sig.getS().toByteArray(); /* Remove first zero sign byte, if present */ if ((s.length > 1) && (s[0] == 0x00)) tw.writeString(s, 1, s.length - 1); else tw.writeString(s, 0, s.length); return tw.getBytes(); }
public static RSASignature decodeSSHRSASignature(byte[] sig) throws IOException { TypesReader tr = new TypesReader(sig); String sig_format = tr.readString(); if (sig_format.equals("ssh-rsa") == false) throw new IOException("Peer sent wrong signature format"); /* S is NOT an MPINT. "The value for 'rsa_signature_blob' is encoded as a string * containing s (which is an integer, without lengths or padding, unsigned and in * network byte order)." See also below. */ byte[] s = tr.readByteString(); if (s.length == 0) throw new IOException("Error in RSA signature, S is empty."); if (log.isEnabled()) { log.log(80, "Decoding ssh-rsa signature string (length: " + s.length + ")"); } if (tr.remain() != 0) throw new IOException("Padding in RSA signature!"); return new RSASignature(new BigInteger(1, s)); }
BigInteger s = ds.getS();
@Deprecated public static RSASignature generateSignature(byte[] message, RSAPrivateKey pk) throws IOException { SHA1 md = new SHA1(); md.update(message); byte[] sha_message = new byte[md.getDigestLength()]; md.digest(sha_message); byte[] der_header = new byte[] { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 }; int rsa_block_len = (pk.getN().bitLength() + 7) / 8; int num_pad = rsa_block_len - (2 + der_header.length + sha_message.length) - 1; if (num_pad < 8) throw new IOException("Cannot sign with RSA, message too long"); byte[] sig = new byte[der_header.length + sha_message.length + 2 + num_pad]; sig[0] = 0x01; for (int i = 0; i < num_pad; i++) { sig[i + 1] = (byte) 0xff; } sig[num_pad + 1] = 0x00; System.arraycopy(der_header, 0, sig, 2 + num_pad, der_header.length); System.arraycopy(sha_message, 0, sig, 2 + num_pad + der_header.length, sha_message.length); BigInteger m = new BigInteger(1, sig); BigInteger s = m.modPow(pk.getD(), pk.getN()); return new RSASignature(s); }
BigInteger s = ds.getS();
public static RSASignature generateSignature(byte[] message, RSAPrivateKey pk) throws IOException { SHA1 md = new SHA1(); md.update(message); byte[] sha_message = new byte[md.getDigestLength()]; md.digest(sha_message); byte[] der_header = new byte[] { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 }; int rsa_block_len = (pk.getN().bitLength() + 7) / 8; int num_pad = rsa_block_len - (2 + der_header.length + sha_message.length) - 1; if (num_pad < 8) throw new IOException("Cannot sign with RSA, message too long"); byte[] sig = new byte[der_header.length + sha_message.length + 2 + num_pad]; sig[0] = 0x01; for (int i = 0; i < num_pad; i++) { sig[i + 1] = (byte) 0xff; } sig[num_pad + 1] = 0x00; System.arraycopy(der_header, 0, sig, 2 + num_pad, der_header.length); System.arraycopy(sha_message, 0, sig, 2 + num_pad + der_header.length, sha_message.length); BigInteger m = new BigInteger(1, sig); BigInteger s = m.modPow(pk.getD(), pk.getN()); return new RSASignature(s); }
BigInteger s = ds.getS();
public static RSASignature generateSignature(byte[] message, RSAPrivateKey pk) throws IOException { SHA1 md = new SHA1(); md.update(message); byte[] sha_message = new byte[md.getDigestLength()]; md.digest(sha_message); byte[] der_header = new byte[] { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 }; int rsa_block_len = (pk.getN().bitLength() + 7) / 8; int num_pad = rsa_block_len - (2 + der_header.length + sha_message.length) - 1; if (num_pad < 8) throw new IOException("Cannot sign with RSA, message too long"); byte[] sig = new byte[der_header.length + sha_message.length + 2 + num_pad]; sig[0] = 0x01; for (int i = 0; i < num_pad; i++) { sig[i + 1] = (byte) 0xff; } sig[num_pad + 1] = 0x00; System.arraycopy(der_header, 0, sig, 2 + num_pad, der_header.length); System.arraycopy(sha_message, 0, sig, 2 + num_pad + der_header.length, sha_message.length); BigInteger m = new BigInteger(1, sig); BigInteger s = m.modPow(pk.getD(), pk.getN()); return new RSASignature(s); }