List of usage examples for java.lang String String
public String(StringBuilder builder)
From source file:RequestCampaign.java
public static void main(String[] args) { System.out.println("Executing Request Campaign"); try {/* ww w .j a va 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 ParamsRequestCampaign request = new ParamsRequestCampaign(); request.setSource(ReqCampSourceType.MKTOWS); ObjectFactory objectFactory = new ObjectFactory(); JAXBElement<Integer> campaignId = objectFactory.createParamsRequestCampaignCampaignId(4496); request.setCampaignId(campaignId); ArrayOfLeadKey leadKeyList = new ArrayOfLeadKey(); LeadKey key = new LeadKey(); key.setKeyType(LeadKeyRef.EMAIL); key.setKeyValue("lead@company.com"); LeadKey key2 = new LeadKey(); key2.setKeyType(LeadKeyRef.EMAIL); key2.setKeyValue("anotherlead@company.com"); leadKeyList.getLeadKeies().add(key); leadKeyList.getLeadKeies().add(key2); JAXBElement<ArrayOfLeadKey> arrayOfLeadKey = objectFactory .createParamsRequestCampaignLeadList(leadKeyList); request.setLeadList(arrayOfLeadKey); SuccessRequestCampaign result = port.requestCampaign(request, header); JAXBContext context = JAXBContext.newInstance(SuccessRequestCampaign.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:OldExtractor.java
/** * @param args the command line arguments *//* w w w.j ava2 s. co m*/ public static void main(String[] args) { // TODO code application logic here String bingUrl = "https://api.datamarket.azure.com/Bing/Search/Web?$top=10&$format=Atom&Query=%27gates%27"; //Provide your account key here. String accountKey = "ghTYY7wD6LpyxUO9VRR7e1f98WFhHWYERMcw87aQTqQ"; // String accountKey = "xqbCjT87/MQz25JWdRzgMHdPkGYnOz77IYmP5FUIgC8"; byte[] accountKeyBytes = Base64.encodeBase64((accountKey + ":" + accountKey).getBytes()); String accountKeyEnc = new String(accountKeyBytes); try { URL url = new URL(bingUrl); URLConnection urlConnection = url.openConnection(); urlConnection.setRequestProperty("Authorization", "Basic " + accountKeyEnc); InputStream inputStream = (InputStream) urlConnection.getContent(); byte[] contentRaw = new byte[urlConnection.getContentLength()]; inputStream.read(contentRaw); String content = new String(contentRaw); //System.out.println(content); try { File file = new File("Results.xml"); FileWriter fileWriter = new FileWriter(file); fileWriter.write(content); //fileWriter.write("a test"); fileWriter.flush(); fileWriter.close(); } catch (IOException e) { System.out.println(e); } DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { //System.out.println("here"); //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file Document dom = db.parse("Results.xml"); Element docEle = (Element) dom.getDocumentElement(); //get a nodelist of elements NodeList nl = docEle.getElementsByTagName("d:Url"); if (nl != null && nl.getLength() > 0) { for (int i = 0; i < nl.getLength(); i++) { //get the employee element Element el = (Element) nl.item(i); // System.out.println("here"); System.out.println(el.getTextContent()); //get the Employee object //Employee e = getEmployee(el); //add it to list //myEmpls.add(e); } } NodeList n2 = docEle.getElementsByTagName("d:Title"); if (n2 != null && n2.getLength() > 0) { for (int i = 0; i < n2.getLength(); i++) { //get the employee element Element e2 = (Element) n2.item(i); // System.out.println("here"); System.out.println(e2.getTextContent()); //get the Employee object //Employee e = getEmployee(el); //add it to list //myEmpls.add(e); } } NodeList n3 = docEle.getElementsByTagName("d:Description"); if (n3 != null && n3.getLength() > 0) { for (int i = 0; i < n3.getLength(); i++) { //get the employee element Element e3 = (Element) n3.item(i); // System.out.println("here"); System.out.println(e3.getTextContent()); //get the Employee object //Employee e = getEmployee(el); //add it to list //myEmpls.add(e); } } } catch (SAXException se) { se.printStackTrace(); } catch (ParserConfigurationException pe) { pe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } } catch (IOException e) { System.out.println(e); } //The content string is the xml/json output from Bing. }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); KeyPairGenerator keyGen = KeyPairGenerator.getInstance("ECDH", "BC"); EllipticCurve curve = new EllipticCurve( new ECFieldFp(new BigInteger("fffffffffffffffffffffffffffffffeffffffffffffffff", 16)), new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16)); ECParameterSpec ecSpec = new ECParameterSpec(curve, new ECPoint(new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16)), new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), 1); keyGen.initialize(ecSpec, new SecureRandom()); KeyAgreement aKeyAgree = KeyAgreement.getInstance("ECDH", "BC"); KeyPair aPair = keyGen.generateKeyPair(); KeyAgreement bKeyAgree = KeyAgreement.getInstance("ECDH", "BC"); KeyPair bPair = keyGen.generateKeyPair(); aKeyAgree.init(aPair.getPrivate());//from www. j a v a 2 s .c o m bKeyAgree.init(bPair.getPrivate()); aKeyAgree.doPhase(bPair.getPublic(), true); bKeyAgree.doPhase(aPair.getPublic(), true); MessageDigest hash = MessageDigest.getInstance("SHA1", "BC"); System.out.println(new String(hash.digest(aKeyAgree.generateSecret()))); System.out.println(new String(hash.digest(bKeyAgree.generateSecret()))); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { // Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); KeyPairGenerator keyGen = KeyPairGenerator.getInstance("ECDH", "BC"); EllipticCurve curve = new EllipticCurve( new ECFieldFp(new BigInteger("fffffffffffffffffffffffffffffffeffffffffffffffff", 16)), new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16)); ECParameterSpec ecSpec = new ECParameterSpec(curve, new ECPoint(new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16)), new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), 1); keyGen.initialize(ecSpec, new SecureRandom()); KeyAgreement aKeyAgree = KeyAgreement.getInstance("ECDH", "BC"); KeyPair aPair = keyGen.generateKeyPair(); KeyAgreement bKeyAgree = KeyAgreement.getInstance("ECDH", "BC"); KeyPair bPair = keyGen.generateKeyPair(); aKeyAgree.init(aPair.getPrivate());//from ww w . j a v a2 s. c o m bKeyAgree.init(bPair.getPrivate()); aKeyAgree.doPhase(bPair.getPublic(), true); bKeyAgree.doPhase(aPair.getPublic(), true); MessageDigest hash = MessageDigest.getInstance("SHA1", "BC"); System.out.println(new String(hash.digest(aKeyAgree.generateSecret()))); System.out.println(new String(hash.digest(bKeyAgree.generateSecret()))); }
From source file:jotp.java
public static void main(String[] argv) { String seed, passphrase;//ww w. j a va 2 s. c om int seq; otp otpwd; int hashalg; String hashtype; if ((argv.length < 3) || (argv.length > 4)) { System.err.println("usage: jotp sequence seed passphrase" + "[md4|md5]"); return; } seq = new Integer(argv[0]).intValue(); seed = new String(argv[1]); passphrase = new String(argv[2]); if ((argv.length == 3) || argv[3].equals("4") || argv[3].equals("md4") || argv[3].equals("MD4")) { hashtype = "md4"; hashalg = otp.MD4; } else if (argv[3].equals("5") || argv[3].equals("md5") || argv[3].equals("MD5")) { hashtype = "md5"; hashalg = otp.MD5; } else { System.err.println("usage: jotp sequence seed passphrase " + "[4|md4|5|md5]"); return; } otpwd = new otp(seq, seed, passphrase, hashalg); System.out.println("Using " + hashtype + ". Thinking..."); otpwd.calc(); System.out.println(otpwd); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); byte[] input = "www.java2s.com".getBytes(); byte[] keyBytes = new byte[] { 0x73, 0x2f, 0x2d, 0x33, (byte) 0xc8, 0x01, 0x73, 0x2b, 0x72, 0x06, 0x75, 0x6c, (byte) 0xbd, 0x44, (byte) 0xf9, (byte) 0xc1, (byte) 0xc1, 0x03, (byte) 0xdd, (byte) 0xd9, 0x7c, 0x7c, (byte) 0xbe, (byte) 0x8e }; byte[] ivBytes = new byte[] { (byte) 0xb0, 0x7b, (byte) 0xf5, 0x22, (byte) 0xc8, (byte) 0xd6, 0x08, (byte) 0xb8 }; // encrypt the data using precalculated keys Cipher cEnc = Cipher.getInstance("DESede/CBC/PKCS7Padding", "BC"); cEnc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(keyBytes, "DESede"), new IvParameterSpec(ivBytes)); byte[] out = cEnc.doFinal(input); // decrypt the data using PBE char[] password = "password".toCharArray(); byte[] salt = new byte[] { 0x7d, 0x60, 0x43, 0x5f, 0x02, (byte) 0xe9, (byte) 0xe0, (byte) 0xae }; int iterationCount = 2048; PBEKeySpec pbeSpec = new PBEKeySpec(password); SecretKeyFactory keyFact = SecretKeyFactory.getInstance("PBEWithSHAAnd3KeyTripleDES", "BC"); Cipher cDec = Cipher.getInstance("PBEWithSHAAnd3KeyTripleDES", "BC"); Key sKey = keyFact.generateSecret(pbeSpec); cDec.init(Cipher.DECRYPT_MODE, sKey, new PBEParameterSpec(salt, iterationCount)); System.out.println("cipher : " + new String(out)); System.out.println("gen key: " + new String(sKey.getEncoded())); System.out.println("gen iv : " + new String(cDec.getIV())); System.out.println("plain : " + new String(cDec.doFinal(out))); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); SecureRandom random = new SecureRandom(); IvParameterSpec ivSpec = createCtrIvForAES(); Key key = createKeyForAES(256, random); Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding", "BC"); String input = "12345678"; Mac mac = Mac.getInstance("DES", "BC"); byte[] macKeyBytes = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; Key macKey = new SecretKeySpec(macKeyBytes, "DES"); cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); byte[] cipherText = new byte[cipher.getOutputSize(input.length() + mac.getMacLength())]; int ctLength = cipher.update(input.getBytes(), 0, input.length(), cipherText, 0); mac.init(macKey);//w ww .ja va2 s . c om mac.update(input.getBytes()); ctLength += cipher.doFinal(mac.doFinal(), 0, mac.getMacLength(), cipherText, ctLength); cipher.init(Cipher.DECRYPT_MODE, key, ivSpec); byte[] plainText = cipher.doFinal(cipherText, 0, ctLength); int messageLength = plainText.length - mac.getMacLength(); mac.init(macKey); mac.update(plainText, 0, messageLength); byte[] messageHash = new byte[mac.getMacLength()]; System.arraycopy(plainText, messageLength, messageHash, 0, messageHash.length); System.out.println("plain : " + new String(plainText) + " verified: " + MessageDigest.isEqual(mac.doFinal(), messageHash)); }
From source file:SyncLead.java
public static void main(String[] args) { System.out.println("Executing syncLead"); try {/*from w w w . java 2 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 ParamsSyncLead request = new ParamsSyncLead(); LeadRecord key = new LeadRecord(); ObjectFactory objectFactory = new ObjectFactory(); JAXBElement<String> email = objectFactory.createLeadRecordEmail("george@jungle.com"); key.setEmail(email); request.setLeadRecord(key); Attribute attr1 = new Attribute(); attr1.setAttrName("FirstName"); attr1.setAttrValue("George2"); Attribute attr2 = new Attribute(); attr2.setAttrName("LastName"); attr2.setAttrValue("of the Jungle"); ArrayOfAttribute aoa = new ArrayOfAttribute(); aoa.getAttributes().add(attr1); aoa.getAttributes().add(attr2); QName qname = new QName("http://www.marketo.com/mktows/", "leadAttributeList"); JAXBElement<ArrayOfAttribute> attrList = new JAXBElement(qname, ArrayOfAttribute.class, aoa); key.setLeadAttributeList(attrList); MktowsContextHeader headerContext = new MktowsContextHeader(); headerContext.setTargetWorkspace("default"); SuccessSyncLead result = port.syncLead(request, header, headerContext); JAXBContext context = JAXBContext.newInstance(SuccessSyncLead.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:SyncCustomObjects.java
public static void main(String[] args) { System.out.println("Executing Sync Custom Objects"); try {/*from ww 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 ParamsSyncCustomObjects request = new ParamsSyncCustomObjects(); request.setObjTypeName("RoadShow"); JAXBElement<SyncOperationEnum> operation = new ObjectFactory() .createParamsSyncCustomObjectsOperation(SyncOperationEnum.UPSERT); request.setOperation(operation); ArrayOfCustomObj customObjects = new ArrayOfCustomObj(); CustomObj customObj = new CustomObj(); ArrayOfAttribute arrayOfKeyAttributes = new ArrayOfAttribute(); Attribute attr = new Attribute(); attr.setAttrName("MKTOID"); attr.setAttrValue("1090177"); Attribute attr2 = new Attribute(); attr2.setAttrName("rid"); attr2.setAttrValue("rid1"); arrayOfKeyAttributes.getAttributes().add(attr); arrayOfKeyAttributes.getAttributes().add(attr2); JAXBElement<ArrayOfAttribute> keyAttributes = new ObjectFactory() .createCustomObjCustomObjKeyList(arrayOfKeyAttributes); customObj.setCustomObjKeyList(keyAttributes); ArrayOfAttribute arrayOfValueAttributes = new ArrayOfAttribute(); Attribute city = new Attribute(); city.setAttrName("city"); city.setAttrValue("SanMateo"); Attribute zip = new Attribute(); zip.setAttrName("zip"); zip.setAttrValue("94404"); Attribute state = new Attribute(); state.setAttrName("state"); state.setAttrValue("California"); arrayOfValueAttributes.getAttributes().add(city); arrayOfValueAttributes.getAttributes().add(state); arrayOfValueAttributes.getAttributes().add(zip); JAXBElement<ArrayOfAttribute> valueAttributes = new ObjectFactory() .createCustomObjCustomObjAttributeList(arrayOfValueAttributes); customObj.setCustomObjAttributeList(valueAttributes); customObjects.getCustomObjs().add(customObj); SuccessSyncCustomObjects result = port.syncCustomObjects(request, header); JAXBContext context = JAXBContext.newInstance(SuccessSyncCustomObjects.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:com.lightboxtechnologies.spectrum.Uploader.java
public static void main(String[] args) throws Exception { final Configuration conf = new Configuration(); final String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length != 1) { System.err.println("Usage: Uploader <dest path>"); System.err.println("Writes data to HDFS path from stdin"); System.exit(2);//from w w w . j a v a 2 s .c o m } MessageDigest hasher = FsEntryUtils.getHashInstance("MD5"); DigestInputStream hashedIn = new DigestInputStream(System.in, hasher); FileSystem fs = FileSystem.get(conf); Path path = new Path(otherArgs[0]); FSDataOutputStream outFile = fs.create(path, true); IOUtils.copyLarge(hashedIn, outFile, new byte[1024 * 1024]); System.out.println(new String(Hex.encodeHex(hasher.digest()))); }