The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Technical SEO Issues
    4. Generating a signature and expires in java

    Generating a signature and expires in java

    Technical SEO Issues
    3 1 417
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • TRich50
      TRich50 last edited by

      Hello,

      I am developing a tool for my company to get stats from SeoMoz using your API.  During development, I have been using the example signature and expires values which are auto-generated for me.  Now that testing is complete, my code will need to generate these values.  I have been googling looking for a resource demonstrating how to do this using Java, but I have not found a good example.  I was hoping that someone at SeoMoz would have a resource or an example that they could share.

      The email associated with this account belongs to a non-developer, so if a response is provided via email in addition to the forum, sending it to my email would be much appreciated.

      Thank you,

      Anthony

      aruffino@ignitemedia.com

      1 Reply Last reply Reply Quote 0
      • TRich50
        TRich50 last edited by

        There has been no response from SeoMoz on this forum or to my email.

        Please provide some feedback.  I am afraid If I cannot solve this issue I will be forced to cancel our account as it is not practical for me to manually load the sample signature and expired value on a daily basis.

        1 Reply Last reply Reply Quote 0
        • TRich50
          TRich50 last edited by

          Never mind,  I have come up with a solution:

          package com.yourpackage.signature;

          import java.io.IOException;
          import java.security.InvalidKeyException;
          import java.security.NoSuchAlgorithmException;
          import java.util.Date;

          import javax.crypto.Mac;
          import javax.crypto.spec.SecretKeySpec;

          import org.apache.geronimo.mail.util.Base64; //can be whichever flavor of encoder you'd like

          public class SignatureGenerator {

          public static final String ACCESS_ID = "member-XXXXXXX";
              public static final String SECRET_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXx";

          //expireTime should be in seconds since Jan 1 1970 : new Date().getTime()/1000) + X
              public static String generateSignature(String data, String key, String expireTime, String algorithm)
                      throws InvalidKeyException, NoSuchAlgorithmException, IOException {

          data += expireTime;

          byte[] hmacData = null;

          SecretKeySpec secretKey = new SecretKeySpec(key.getBytes("UTF-8"),
                              algorithm);
                      Mac mac = Mac.getInstance(algorithm);
                      mac.init(secretKey);
                      hmacData = mac.doFinal(data.getBytes("UTF-8"));

          String encoded = new String(Base64.encode(hmacData));

          return encoded;
              }

          public static void main(String[] args) {
                  try {

          Long longTime = new Long(new Date().getTime()/1000) + 60;

          System.out.println(longTime);

          String data = ACCESS_ID + "\n";

          System.out.println(generateSignature(data, SECRET_KEY, String.valueOf(longTime), "HMACSHA1"));
                  } catch (Exception e) {
                      e.printStackTrace();
                  }

          }

          }

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          • No Java, No Content..?
            Pipistrella
            Pipistrella
            0
            4
            110

          • XML Sitemap Generators
            GPainter
            GPainter
            0
            2
            62

          • Expires Header
            MichaelC-15022
            MichaelC-15022
            0
            2
            137

          • Auto generated pages
            GeorgeAndrews
            GeorgeAndrews
            0
            5
            420

          • Does Google index has expiration?
            informatica810
            informatica810
            0
            3
            169

          • How can the search engines can crawl my java script generated web pages
            randfish
            randfish
            0
            2
            1.3k

          • Grabbing Expired Domains
            StreamlineMetrics
            StreamlineMetrics
            0
            6
            812

          • Problem generating backlinks
            jay.raman
            jay.raman
            0
            5
            424

          Get started with Moz Pro!

          Unlock the power of advanced SEO tools and data-driven insights.

          Start my free trial
          Products
          • Moz Pro
          • Moz Local
          • Moz API
          • Moz Data
          • STAT
          • Product Updates
          Moz Solutions
          • SMB Solutions
          • Agency Solutions
          • Enterprise Solutions
          • Digital Marketers
          Free SEO Tools
          • Domain Authority Checker
          • Link Explorer
          • Keyword Explorer
          • Competitive Research
          • Brand Authority Checker
          • Local Citation Checker
          • MozBar Extension
          • MozCast
          Resources
          • Blog
          • SEO Learning Center
          • Help Hub
          • Beginner's Guide to SEO
          • How-to Guides
          • Moz Academy
          • API Docs
          About Moz
          • About
          • Team
          • Careers
          • Contact
          Why Moz
          • Case Studies
          • Testimonials
          Get Involved
          • Become an Affiliate
          • MozCon
          • Webinars
          • Practical Marketer Series
          • MozPod
          Connect with us

          Contact the Help team

          Join our newsletter
          Moz logo
          © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
          • Accessibility
          • Terms of Use
          • Privacy