Examples of MessageDigest


Examples of com.sun.midp.crypto.MessageDigest

     */
    public static byte[] getHash(byte[] data, int offset, int length) {

        byte[] tmp = new byte[20];
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(data, offset, length);
            md.digest(tmp, 0, tmp.length);
        } catch (GeneralSecurityException e) {
            // algorithm not found - not in this implementation
            throw new RuntimeException(
                "SHA-1 algorithm for MessageDigest not supported");
        }
View Full Code Here

Examples of java.security.MessageDigest

        MockObserver peerObserver=new MockObserver();
        peer.setObserver(peerObserver);
        peer.keyServer=false;


        MessageDigest digest=MessageDigest.getInstance("MD5");
        digest.reset();
        digest.update(server.getDesKey().getEncoded());

        String symVersion=new String(digest.digest(), "UTF-8");

        // encrypt and send an initial message to peer
        Cipher cipher=server.getSymEncodingCipher();
        Message msg=new Message();
        msg.setBuffer(cipher.doFinal("hello".getBytes()));
View Full Code Here

Examples of java.security.MessageDigest

     * @param source the source String
     * @return the MD5 hashed version of the string
     */
    public static String md5(String source) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] bytes = md.digest(source.getBytes());
            return getString(bytes);
        } catch (Exception e) {
            return null;
        }
    }
View Full Code Here

Examples of java.security.MessageDigest

     * @param source the source String
     * @return the MD5 hashed version of the string
     */
    public static String sha(String source) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            byte[] bytes = md.digest(source.getBytes());
            return getString(bytes);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
View Full Code Here

Examples of java.security.MessageDigest

        String messageText="hello this is a test message";
        Cipher cipher=encrypt2.getSymEncodingCipher();
        byte[] encodedBytes=cipher.doFinal(messageText.getBytes());
        assert !new String(encodedBytes).equals(messageText);

        MessageDigest digest=MessageDigest.getInstance("MD5");
        digest.reset();
        digest.update(encrypt.getDesKey().getEncoded());

        String symVersion=new String(digest.digest(), "UTF-8");

        Message msg=new Message(null, null, encodedBytes);
        msg.putHeader(ENCRYPT_ID, new ENCRYPT.EncryptHeader(ENCRYPT.EncryptHeader.ENCRYPT, symVersion));
        Event event=new Event(Event.MSG, msg);
        encrypt.up(event);
View Full Code Here

Examples of java.security.MessageDigest

        String messageText="hello this is a test message";
        Cipher cipher=encrypt2.getSymEncodingCipher();
        byte[] encodedBytes=cipher.doFinal(messageText.getBytes());
        assert !new String(encodedBytes).equals(messageText);

        MessageDigest digest=MessageDigest.getInstance("MD5");
        digest.reset();
        digest.update(encrypt2.getDesKey().getEncoded());

        String symVersion=new String(digest.digest());

        Message msg=new Message(null, null, encodedBytes);
        msg.putHeader(ENCRYPT_ID, new ENCRYPT.EncryptHeader(ENCRYPT.EncryptHeader.ENCRYPT, symVersion));
        Event event=new Event(Event.MSG, msg);
        encrypt.up(event);
View Full Code Here

Examples of java.security.MessageDigest

        encrypt.setObserver(observer);

        // produce encrypted message
        Cipher cipher=encrypt.getSymEncodingCipher();

        MessageDigest digest=MessageDigest.getInstance("MD5");
        digest.reset();
        digest.update(encrypt.getDesKey().getEncoded());

        String symVersion=new String(digest.digest(), "UTF-8");

        encrypt.keyServer=false;
        Message msg=new Message();
        msg.setBuffer(cipher.doFinal("hello".getBytes()));
        msg.putHeader(ENCRYPT_ID, new EncryptHeader(EncryptHeader.ENCRYPT, symVersion));
View Full Code Here

Examples of java.security.MessageDigest

  private Password(){
  }

  public synchronized String encrypt(String plaintext)
  {
    MessageDigest md = null;
    try
    {
      md = MessageDigest.getInstance("SHA1");
    }
    catch(NoSuchAlgorithmException noSuchAlgorithmException)
    {
    noSuchAlgorithmException.printStackTrace();
    }//end of catch block
   
    try
    {
      md.update(plaintext.getBytes("UTF-8"));
    }
    catch(UnsupportedEncodingException unsupportedEncodingException)
    {
    unsupportedEncodingException.printStackTrace();
    }//end of catch block
    byte raw[] = md.digest();
    String hash = (new BASE64Encoder()).encode(raw);
    return hash;
  }//end of encrypt(String plaintext)
View Full Code Here

Examples of java.security.MessageDigest

      KeyAgreement ka = KeyAgreement.getInstance(ALGORITHM);
      ka.init(privateKey);
      ka.doPhase(publicKey, true);
      byte[] secret = ka.generateSecret();

      MessageDigest sha = MessageDigest.getInstance(DIGEST);
      byte[] hash = sha.digest(secret);
      byte[] symKey = new byte[keySize / 8];
      System.arraycopy(hash, 0, symKey, 0, symKey.length);
      return SymmetricCryptor.getSymmectricCryptor(symKey);
    } catch (NoSuchAlgorithmException e) {
      throw new CryptoException(e);
View Full Code Here

Examples of java.security.MessageDigest

     * @throws IOException
     * @throws NoSuchAlgorithmException
     */
    private String md5(InputStream is) throws IOException,
            NoSuchAlgorithmException {
        MessageDigest digest = MessageDigest.getInstance("MD5");
        DigestInputStream dis = new DigestInputStream(is, digest);

        byte[] buffer = new byte[1024];

        int read = dis.read(buffer);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.