How to connect kepware-ua-server in Eclipse Milo - opc-ua

I have a client.der generated by Kepware opc ua configuration.How to use it convert to KeyPair?
File clientFile = new File("C:\\Users\\Rex\\Desktop\\client.der");
FileInputStream privatekeyfile = new FileInputStream(clientFile);
Security.addProvider(new BouncyCastleProvider());
PEMParser pemParser = new PEMParser(new InputStreamReader(privatekeyfile));
Object object = pemParser.readObject();
PEMDecryptorProvider pemDecryptorProvider = new JcePEMDecryptorProviderBuilder().build(certificate.getPublicKey().toString().toCharArray());
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
keyPair = converter.getKeyPair(((PEMEncryptedKeyPair) object).decryptKeyPair(pemDecryptorProvider));
Object object = pemParser.readObject(); the object always is null.

Related

Using Temp File Method for signing in iText Java instead of depending on System Memory

We are using PKCS7 Signatures and are signing a document on the server using a signature created on the client. We are creating Pdf Objects in memory, and want to switch to a system where we do not need to depend on system memory. Currently, I am saving the PdfSignatureAppearance Object created while generating hash in session,and then using this object from session when I receive a response from client (Signed Hash Content). Could you please help me figure out a way through which I do not need to save the PdfSignatureAppearance object in session and can directly use the Temp File for signing?
First, we generate a hash of file after inserting signature appearance as shown in the code below:
File file = new File("To be signed file location")
char version = '\u0000'
ByteArrayOutputStream out = new ByteArrayOutputStream()
String outputFile = "Signed file name"
FileOutputStream fileOutputStream = new FileOutputStream(outputFile)
PdfReader pdfReader = new PdfReader(new FileInputStream(file.absolutePath))
PdfStamper stamper = new PdfStamper(pdfReader, out, version, true)
PdfFormField pdfFormField = PdfFormField.createSignature(stamper.getWriter())
String signatureName = "Signature1"
pdfFormField.setWidget(new Rectangle((float) 20, (float) 20, (float) 100, (float) 60), (PdfName) null)
pdfFormField.setFlags(4)
pdfFormField.put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g"))
pdfFormField.setFieldName(signatureName)
pdfFormField.setPage(1)
stamper.addAnnotation(pdfFormField, i)
stamper.close()
pdfReader = new PdfReader(out.toByteArray())
stamper = PdfStamper.createSignature(pdfReader, fileOutputStream, version, (File) null, true)
PdfSignatureAppearance appearance = stamper.getSignatureAppearance()
appearance.setLayer2Text("Digitally Signed by Name")
appearance.setImage(Image.getInstance(esignRequestCO.logoLocation))
appearance.setAcro6Layers(true)
Calendar cal = Calendar.getInstance()
cal.setTime(new Date())
cal.add(12, 5)
appearance.setSignDate(cal)
appearance.setVisibleSignature(signatureName)
int contentEstimated = 16384
HashMap<PdfName, Integer> exc = new HashMap()
exc.put(PdfName.CONTENTS, contentEstimated * 2 + 2)
PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, PdfName.ADBE_PKCS7_DETACHED)
dic.setReason(appearance.getReason())
dic.setLocation(appearance.getLocation())
dic.setDate(new PdfDate(appearance.getSignDate()))
appearance.setCryptoDictionary(dic)
appearance.preClose(exc)
InputStream inp = appearance.getRangeStream()
byte[] bytes = IOUtils.toByteArray(inp)
String hash = DigestUtils.sha256Hex(bytes)
As soon as we get the signed content, we insert the content in the file using same appearance object as shown below:
int contentEstimated = 16384
PdfSignatureAppearance appearance = "PdfSignatureAppearance object from session generated in previous step"
byte[] p7barray = "signed content here".bytes
byte[] paddedSig = new byte[contentEstimated]
System.arraycopy(p7barray, 0, paddedSig, 0, p7barray.length)
PdfDictionary dic2 = new PdfDictionary()
dic2.put(PdfName.CONTENTS, (new PdfString(paddedSig)).setHexWriting(true))
appearance.close(dic2)

Connection String Error in OleDB

I am trying to Import Excel file through asp.net code. but I am getting ArgumentException when I am trying to create OleDbConnection
An OLE DB Provider was not specified in the ConnectionString. An
example would be, 'Provider=SQLOLEDB;'.
Here is the code
if (FileUpload1.HasFile)
{
string path = string.Concat((Server.MapPath("~/temp/"+FileUpload1.FileName)));
FileUpload1.PostedFile.SaveAs(path);
OleDbConnection oleCon = new OleDbConnection("Povider=Microsoft.Ace.OLEDB.12.0;Data Source="+path+";Extended Properties = Excel 12.0;");
OleDbCommand cmd = new OleDbCommand("select * from [Sheet1$]",oleCon);
OleDbDataAdapter dtap = new OleDbDataAdapter(cmd);
oleCon.Open();
DbDataReader rdr = cmd.ExecuteReader();
string con_str = #"Data source = .;Initial Catalog=practiceDB;Integrated security=True";
SqlBulkCopy bulkInsert = new SqlBulkCopy(con_str);
bulkInsert.DestinationTableName="Excel";
bulkInsert.WriteToServer(rdr);
oleCon.Close();
Array.ForEach(Directory.GetFiles((Server.MapPath("~/temp/"))),File.Delete);
Response.Write("<script>alert('Inserted')</script>");

Can't add TaxService to QBO with .NET SDK

How do I create a tax rate in QBO using API v3 and the TaxService resource? When I try to add it the same way as I would any other object, Visual Studio gives me this error: "The type 'Intuit.Ipp.Data.TaxService' cannot be used as type parameter 'T' in the generic type or method Intuit.Ipp.DataService.DataService.Add(T)'. There is no implicit reference conversion from 'Intuit.Ipp.Data.TaxService' to 'Intuit.Ipp.Data.IEntity'."
Here's the code:
Intuit.Ipp.Data.TaxService ts = new Intuit.Ipp.Data.TaxService();
// Populate fields here...
DataService ds = new DataService(ServiceContext);
Intuit.Ipp.Data.TaxService newTs = ds.Add<Intuit.Ipp.Data.TaxService>(ts);
Use GlobalTaxService endpoint and JSON format only. Try this code:
GlobalTaxService taxSvc = new GlobalTaxService(context);
Intuit.Ipp.Data.TaxService taxCodetobeAdded = new Data.TaxService();
taxCodetobeAdded.TaxCode = "taxC_" + Guid.NewGuid().ToString("N");
QueryService<TaxAgency> taxagency = new QueryService<TaxAgency>(context);
TaxAgency taxagencyResult = taxagency.ExecuteIdsQuery("select * from TaxAgency").FirstOrDefault<TaxAgency>();
List<TaxRateDetails> lstTaxRate = new List<TaxRateDetails>();
TaxRateDetails taxdetail1 = new TaxRateDetails();
taxdetail1.TaxRateName = "taxR1_" + Guid.NewGuid().ToString("N");
taxdetail1.RateValue = 3m;
taxdetail1.RateValueSpecified = true;
taxdetail1.TaxAgencyId = taxagencyResult.Id.ToString();
taxdetail1.TaxApplicableOn = TaxRateApplicableOnEnum.Sales;
taxdetail1.TaxApplicableOnSpecified = true;
lstTaxRate.Add(taxdetail1);
TaxRateDetails taxdetail2 = new TaxRateDetails();
taxdetail2.TaxRateName = "taxR2_" + Guid.NewGuid().ToString("N");
taxdetail2.RateValue = 2m;
taxdetail2.RateValueSpecified = true;
taxdetail2.TaxAgencyId = taxagencyResult.Id.ToString();
taxdetail2.TaxApplicableOn = TaxRateApplicableOnEnum.Sales;
taxdetail2.TaxApplicableOnSpecified = true;
lstTaxRate.Add(taxdetail2);
//TaxRateDetails taxdetail3 = new TaxRateDetails();
//taxdetail3.TaxRateName = "rate298";
//taxdetail3.TaxRateId = "2";
//lstTaxRate.Add(taxdetail3);
taxCodetobeAdded.TaxRateDetails = lstTaxRate.ToArray();
Intuit.Ipp.Data.TaxService taxCodeAdded = taxSvc.AddTaxCode(taxCodetobeAdded);

salesforce mobile sdk create related object

I have Sample_Product__c custom object, and wanted to create object with relational field's external id:
final Map<String, Object> prod = new HashMap<String, Object>();
prod.put("External_ID__c", obj.getString("medicineName"));
final Map < String, Object > sample = new HashMap < String, Object > ();
sample.put("Product__r", prod);
sample.put("LotNumber__c", obj.getString("medicineSerialNo"));
sample.put("GivenDate__c", format.format(givenDate));
sample.put("ExpiredDate__c", format.format(expireDate));
sample.put("GivenNumber__c", obj.getString("medicineQuantity"));
sample.put("Call__c", callid);
RestRequest.getRequestForCreate(getString(R.string.api_version), "Sample_Product__c", sample);
This gives error as, Product__r should be SObject...
In PHP, I was doing this like so:
$sfobject = new stdclass();
$sfobject->External_ID__c = "...";
$sample->Product__r = $sfobject;
But have no idea how to achieve this with salesforce mobile SDK... hope someone knows, thanks!

How to force the Plugin on Post-Operation to Submit?

I have a plugin in post-operation witch need to create a folder on sharepoint via webservice, to do that, my plugin calls a webservice to execute a FechXML to get the info from the entity, but the problem is that entity still not exist, and it give me Null.
How do i force the plugin to submit/save the data to my FechXml to work?
PLUGIN CODE:
try
{
Entity entity;
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "fcg_processos")
{
throw new InvalidPluginExecutionException("Ocorreu um erro no PlugIn Create Folder.");
}
}
else
{
throw new InvalidPluginExecutionException("Ocorreu um erro no PlugIn Create Folder.");
}
processosid = (Guid)((Entity)context.InputParameters["Target"])["fcg_processosid"];
string processoid2 = processosid.ToString();
PluginSharepointProcessos.ServiceReference.PrxActivityResult result = log.CreateFolderSP("Processo", processoid2);
string resultado = result.xmlContent;
if (result.retCode > 0)
{
throw new InvalidPluginExecutionException("Ocorreu um erro na criação do Folder do Processo.");
}
WEBSERVICE CODE:
{
//WEBSERVICE TO CALL XML FROM ENTITY
PrxActivityResult Processo = ProcessoFetch2("", "", guid);
string stxml;
stxml = Processo.XmlContent;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(stxml);
XmlNodeList nodeList = xmlDoc.SelectNodes("resultset/result");
List<string[]> lista = new List<string[]>();
string[] strs = new string[7];
if (nodeList.Count != 0)//verificar o numero de registos
{
foreach (XmlNode xmlnode in nodeList)
{
if (xmlnode.SelectSingleNode("//fcg_numero") != null)
strs[2] = xmlnode.SelectSingleNode("//fcg_numero").InnerText;
else
strs[2] = "";
if (xmlnode.SelectSingleNode("//Concurso.fcg_numero") != null)
strs[3] = xmlnode.SelectSingleNode("//Concurso.fcg_numero").InnerText;
else
strs[3] = "";
}
}
IwsspClient FmwSharepoint = new IwsspClient();
PrxActivityResult folderresult = new PrxActivityResult();
List<ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave> arrayfields = new List<ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave>();
ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave nprocesso = new ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave();
nprocesso.Key = "FCG_Numero_Processo";
nprocesso.value = strs[2];
arrayfields.Add(nprocesso);
ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave npconcurso = new ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave();
npconcurso.Key = "FCG_Numero_Concurso";
npconcurso.value = strs[3];
arrayfields.Add(npconcurso);
ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave npguid = new ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave();
npguid.Key = "FCG_Guid_CRM";
npguid.value = guid;
arrayfields.Add(npguid);
folderresult = FmwSharepoint.CreateFolder("http://localhost/folder", "Processos", strs[2], arrayfields.ToArray());
res = folderresult;
}
When a plugin runs on the Post-Operation, it is still within the database transaction, and it hasn't actually been committed to the database. Any calls done with the service reference passed in as a part of the Plugin Context will be executed within the context on the database transaction and you will be able to retrieve the newly created/updated values. If you create a brand new OrganizationServiceProxy (Which I'm guessing is what you're doing), it will execute outside of the database transaction, and will not see the newly created / updated values.
As #AndyMeyers suggests in his comment (which really should be an answer IMHO), grabbing the data from the plugin context either via a pre/post image or the target is ideal since it eliminates another database call. If you're having to lookup records that may have been created by another plugin that fired earlier, you'll need to use the IOrganizationService that is included in the plugin context.
I had no option and I used this code to run webservice based on image and forget the FecthXml, as mentioned, i get all info from the Image on the post operation and send back to the WebService. Thanks, here is the code:
entity = (Entity)context.InputParameters["Target"];
concursid = (Guid)entity.Attributes["fcg_concursid"];
guid = concursid.ToString();
string npconcurs = (string)entity.Attributes["fcg_numer"];
nconcurs= npconcurs;
EntityReference nprograma = (EntityReference)entity.Attributes["fcg_unidadeorganica"];
program = nprogram.Name;
if (entity.LogicalName != "fcg_concurs")