Example usage for javax.crypto.spec SecretKeySpec SecretKeySpec

List of usage examples for javax.crypto.spec SecretKeySpec SecretKeySpec

Introduction

In this page you can find the example usage for javax.crypto.spec SecretKeySpec SecretKeySpec.

Prototype

public SecretKeySpec(byte[] key, String algorithm) 

Source Link

Document

Constructs a secret key from the given byte array.

Usage

From source file:GetLead.java

public static void main(String[] args) {
    System.out.println("Executing Get Lead");
    try {/* www .j a  v a  2  s  .  c  om*/

        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();

        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsGetLead request = new ParamsGetLead();

        LeadKey key = new LeadKey();
        key.setKeyType(LeadKeyRef.EMAIL);
        key.setKeyValue("t@t.com");
        request.setLeadKey(key);

        SuccessGetLead result = port.getLead(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessGetLead.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:DescribeMObject.java

public static void main(String[] args) {

    System.out.println("Executing Describe MObject");
    try {//from   w  w w.  j  a v a 2  s. c  o m
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsDescribeMObject request = new ParamsDescribeMObject();
        request.setObjectName("ActivityRecord");

        SuccessDescribeMObject result = port.describeMObject(request, header);
        JAXBContext context = JAXBContext.newInstance(SuccessDescribeMObject.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:GetImportToListStatus.java

public static void main(String[] args) {
    System.out.println("Executing Get Import To List Status");
    try {/*from   w ww  .j  a  v  a 2s  .c o m*/
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsGetImportToListStatus request = new ParamsGetImportToListStatus();

        request.setProgramName("Trav-Demo-Program");
        request.setListName("Trav-Test-List");

        SuccessGetImportToListStatus result = port.getImportToListStatus(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessGetImportToListStatus.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:DeleteMObjects.java

public static void main(String[] args) {
    System.out.println("Executing Delete MObjects");
    try {// ww w .j  a  va  2  s.  c om
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsDeleteMObjects request = new ParamsDeleteMObjects();

        MObject mobj = new MObject();
        mobj.setType("Opportunity");
        mobj.setId(4);

        MObject mobj2 = new MObject();
        mobj2.setType("Opportunity");
        mobj2.setId(7);

        ArrayOfMObject objList = new ArrayOfMObject();
        objList.getMObjects().add(mobj);
        objList.getMObjects().add(mobj2);

        request.setMObjectList(objList);

        SuccessDeleteMObjects result = port.deleteMObjects(request, header);
        JAXBContext context = JAXBContext.newInstance(SuccessDeleteMObjects.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:getMObjects.java

public static void main(String[] args) {
    System.out.println("Executing Get MObjects");
    try {/*w  w w .j av a2 s. c o m*/
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsGetMObjects request = new ParamsGetMObjects();
        request.setType("Program");

        MObjCriteria criteria = new MObjCriteria();
        criteria.setAttrName("Id");
        criteria.setComparison(ComparisonEnum.LE);
        criteria.setAttrValue("1010");

        MObjCriteria criteria2 = new MObjCriteria();
        criteria2.setAttrName("Name");
        criteria2.setComparison(ComparisonEnum.NE);
        criteria2.setAttrValue("elizprogramtest");

        ArrayOfMObjCriteria mObjCriteria = new ArrayOfMObjCriteria();
        mObjCriteria.getMObjCriterias().add(criteria);
        mObjCriteria.getMObjCriterias().add(criteria2);

        request.setMObjCriteriaList(mObjCriteria);

        SuccessGetMObjects result = port.getMObjects(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessGetMObjects.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:MergeLeads.java

public static void main(String[] args) {
    System.out.println("Executing Merge Lead");
    try {/*from   ww w  . ja  va 2s.  c o m*/
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsMergeLeads request = new ParamsMergeLeads();

        ArrayOfAttribute winningLeadArray = new ArrayOfAttribute();

        Attribute winner = new Attribute();
        winner.setAttrName("IDNUM");
        winner.setAttrValue("2");
        winningLeadArray.getAttributes().add(winner);
        request.setWinningLeadKeyList(winningLeadArray);

        ArrayOfAttribute losingLeadArray = new ArrayOfAttribute();

        Attribute loser = new Attribute();
        loser.setAttrName("IDNUM");
        loser.setAttrValue("15");
        losingLeadArray.getAttributes().add(loser);

        ArrayOfAttribute losingLeadArray2 = new ArrayOfAttribute();
        Attribute loser2 = new Attribute();
        loser2.setAttrName("IDNUM");
        loser2.setAttrValue("16");
        losingLeadArray2.getAttributes().add(loser2);

        ArrayOfKeyList losingKeyList = new ArrayOfKeyList();
        losingKeyList.getKeyLists().add(losingLeadArray);
        losingKeyList.getKeyLists().add(losingLeadArray2);
        request.setLosingLeadKeyLists(losingKeyList);

        SuccessMergeLeads result = port.mergeLeads(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessMergeLeads.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:SyncMObjects.java

public static void main(String[] args) {
    try {/*from   w w  w  .ja  v  a2 s .c om*/
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ////////////////////////////////
        ParamsSyncMObjects request = prepareUpdateProgramRequest();
        // -or-  
        //ParamsSyncMObjects request = prepareCreateOpptyRequest();
        // -or-
        //ParamsSyncMObjects request = prepareCreateOpptyPersonRoleRequest();
        ////////////////////////////////

        SuccessSyncMObjects result = port.syncMObjects(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessSyncMObjects.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:GetCustomObjects.java

public static void main(String[] args) {
    System.out.println("Executing Get Custom Objects");
    try {//  ww  w  .  jav  a  2  s. c  om
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsGetCustomObjects request = new ParamsGetCustomObjects();
        request.setObjTypeName("RoadShow");

        ArrayOfAttribute arrayOfAttribute = new ArrayOfAttribute();

        Attribute attr = new Attribute();
        attr.setAttrName("MKTOID");
        attr.setAttrValue("1090177");
        arrayOfAttribute.getAttributes().add(attr);

        JAXBElement<ArrayOfAttribute> attributes = new ObjectFactory()
                .createParamsGetCustomObjectsCustomObjKeyList(arrayOfAttribute);
        request.setCustomObjKeyList(attributes);

        SuccessGetCustomObjects result = port.getCustomObjects(request, header);
        JAXBContext context = JAXBContext.newInstance(SuccessGetCustomObjects.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:GetCampaignsForSource.java

public static void main(String[] args) {
    System.out.println("Executing Get Campaigns For Source");
    try {/*from  w w  w. j ava  2s  . c om*/
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsGetCampaignsForSource request = new ParamsGetCampaignsForSource();

        request.setSource(ReqCampSourceType.MKTOWS);

        ObjectFactory objectFactory = new ObjectFactory();
        JAXBElement<String> name = objectFactory.createParamsGetCampaignsForSourceName("Trigger");
        request.setName(name);

        JAXBElement<Boolean> exactName = objectFactory.createParamsGetCampaignsForSourceExactName(false);
        request.setExactName(exactName);

        SuccessGetCampaignsForSource result = port.getCampaignsForSource(request, header);

        JAXBContext context = JAXBContext.newInstance(SuccessGetCampaignsForSource.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:GetTags.java

public static void main(String[] args) {

    System.out.println("Executing Get Tags");
    try {// w w w.j ava2 s  .c om
        URL marketoSoapEndPoint = new URL("https://100-AEK-913.mktoapi.com/soap/mktows/2_1" + "?WSDL");
        String marketoUserId = "demo17_1_809934544BFABAE58E5D27";
        String marketoSecretKey = "27272727aa";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        // Create Request
        ParamsGetTags request = new ParamsGetTags();
        ArrayOfTag tags = new ArrayOfTag();

        Tag tag = new Tag();
        tag.setType("Content Channel");
        /*
        ArrayOfString values = new ArrayOfString();
        values.getStringItems().add("SEM");
        values.getStringItems().add("Email");
                 
        tag.setValues(values);
        tags.getTags().add(tag);
                 
        request.setTagList(tags);
        */

        SuccessGetTags result = port.getTags(request, header);
        JAXBContext context = JAXBContext.newInstance(SuccessGetTags.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(result, System.out);

    } catch (Exception e) {
        e.printStackTrace();
    }
}