I have a question about encryption. So I have a code sample that has a key size being chosen, something like 32 bits or something, and I am basically either filling the key size buffer with the password and then zeroes, or null bytes, or a word repeated over and over (Supercalafragalisticexpialidocios). Is there something I am missing about key and IV selection or is this the right way to go? I thought I saw something that automatically chooses the remaining bytes but I don't remember the name of the object. The data security book does not go into this problem at all.
MagnusTheRed90 30 Newbie Poster
I need an end user license agreement for code shared amongst my home projects with other developers. The EULA needs to include a "pay to the order of x" clause, and also needs to include the ability for me to utilze the code at multiple companies that I could participate in. I suspect the EULA may need to be fairly complete, and preclude explicitly illicit usage. If we could have a discussion that would be cool. I was learning about EULA's in college but haven't made one for real life yet.
MagnusTheRed90 30 Newbie Poster
Well thank you very much for replying, I would like to hear from other people too if they would like to comment on it also. I am sort of new to this encryption stuff, and I do believe that this particular aspect of cryptography has never really been commented on online yet. The data security book certainly didn't mention it. I think I am going to add a lookup routine to my other code, such that it doesn't make the same directory twice. I am sort of working on a drive encryptor, which may not be feasible to finish.
MagnusTheRed90 30 Newbie Poster
If I understand it correctly however, the cryptography must be deterministic, therefore it varies by it's input arguments, the symmetric algorithim, the padding mode, the cipher mode, the password, and the iv (could have missed one). You should run the program and compare the hashes which I have displayed on screen. This would essentially create N folders (I have a pathing function). At least post back whether the cipher text varies on your system.
MagnusTheRed90 30 Newbie Poster
Hello, so I have a more complex class in another file, but I have duplicated my trouble on a simpler class which I will show to you. I am trying to base64 encode a path via cipher text, either a good idea or a bad idea. Anyway, I am noticing that the cryptography decrypts, but the cipher text varies and is never the same twice. I was wondering if you could spot why it's doing it. My knee jerk reaction to this is that one of the input variables for the crypto method is changing between calls, but I can't see where it is. Any help would be appreciated, the data security books are to no avail.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO;
namespace EncryptionTest {
class Program {
static void Main(string[] args) {
String plainText = "SomeFolder";
for (int i = 0; i < 100; i++) {
byte[] encryptedA = EncryptBase64(plainText);
//Console.WriteLine("Cipher Text: " + Encoding.ASCII.GetString(encryptedA));
String plainTextB = DecryptBase64(encryptedA);
Console.WriteLine("Plaintext B: " + plainTextB);
Console.WriteLine();
}//end loop
Console.Write("Press any key to continue... ");
Console.ReadKey();
}//end method
/// <summary>
/// Gets the decrypted data.
/// Tested... Works...
/// </summary>
/// <returns></returns>
public static String DecryptBase64(byte[] cipherText) {
SymmetricAlgorithm crypt = System.Security.Cryptography.Aes.Create();
Encoding Encoding = System.Text.Encoding.UTF8;
PaddingMode PaddingMode = System.Security.Cryptography.PaddingMode.ISO10126;
byte[] key = Encoding.GetBytes("Madcat90".PadRight(crypt.Key.Length, '0').ToCharArray(), 0, crypt.Key.Length); ;
byte[] iv = Encoding.GetBytes("Madcat90".PadRight(crypt.IV.Length, '0').ToCharArray(), 0, crypt.IV.Length);
crypt.Padding = PaddingMode;
crypt.Mode = CipherMode.CBC;
crypt.Key = key;
crypt.IV = iv;
Console.WriteLine(crypt.GetType().Name);
Console.WriteLine(crypt.Padding.ToString());
Console.WriteLine(crypt.Mode.ToString());
Console.WriteLine(String.Format("Key: …
MagnusTheRed90 30 Newbie Poster
The following is not exactly what I wanted, it uses looping instead of queries. I do not know a query technique that gets me around the problem with the where statement growing for every login expressed. I also noticed that some of the variables at the top of the program were not what they should have been, it was the date times of the first or second grouping of code.
List<Post> posts = new List<Post>();
User user = new User("Joe Schmoe");
DateTime dateOccurred = DateTime.Now - TimeSpan.FromDays(-4);
user.AddLoginEvent("192.168.1.1", dateOccurred);
Post post = new Post(user, "Something Good... ", dateOccurred.AddMinutes(15));
posts.Add(post);
dateOccurred = DateTime.Now - TimeSpan.FromDays(-3);
user.AddLoginEvent("192.168.1.2", dateOccurred);
post = new Post(user, "Something Bad... ", dateOccurred.AddMinutes(15));
posts.Add(post);
dateOccurred = DateTime.Now - TimeSpan.FromDays(-2);
user.AddLoginEvent("192.168.1.1", dateOccurred);
post = new Post(user, "Something Good... ", dateOccurred.AddMinutes(15));
posts.Add(post);
dateOccurred = DateTime.Now - TimeSpan.FromDays(-1);
user.AddLoginEvent("192.168.1.2", dateOccurred);
post = new Post(user, "Something Bad... ", dateOccurred.AddMinutes(15));
posts.Add(post);
posts = posts.OrderByDescending(p => p.DateOccurred).ToList();
//var query = user.LoginEvents.Join(posts, x => x.User, y => y.User, (x, y) => new { Login = x, Post = y })
// .Where(obj => obj.Login.DateOccurred < obj.Post.DateOccurred)
// .Join(user.LoginEvents, x => x.Login.User, y => y.User, (x, y) => new { Post = x.Post, Login = x.Login, LoginY = y })
// .Where(obj => obj.LoginY.DateOccurred < obj.Post.DateOccurred);
////.Select(obj => new { IpAddress = obj.Login.IpAddress, Content = obj.Post.Content, DateOccurred = obj.Post.DateOccurred });
////.Select(obj => new { IpAddress = obj.Login.IpAddress, Content = obj.Post.Content, DateOccurred = obj.Post.DateOccurred, NextLogin = obj.LoginY });
//var query = from pst in posts
// from …
rproffitt commented: Working code wins over "this would be better if it worked" code. +15
MagnusTheRed90 30 Newbie Poster
Actually this is linq to objects. It is completely runnable on your own system. It makes no database calls yet.
MagnusTheRed90 30 Newbie Poster
Here is a translation to query syntax. From what I have been learning from online sources the three 'from' statements should be cartesioning all the entries, post, logA, and logB. This is useful, but the problem is actually the where statement. The second statement in the where statement is not working correctly. I don't know exactly how to express this.
var query = from pst in posts
from logA in user.LoginEvents
from logB in user.LoginEvents
where pst.DateOccurred > logA.DateOccurred && pst.DateOccurred < logB.DateOccurred
select new { Post = pst, LogA = logA, LogB = logB};
MagnusTheRed90 30 Newbie Poster
The problem appears to be the linq. What it will have to be able to do is sort of interleave the LoginEvents which I am trying to join to twice. Essentially the where clause needs to have a greater than component, and a less than component.
var query = user.LoginEvents.Join(posts, x => x.User, y => y.User, (x, y) => new { Login = x, Post = y })
.Where(obj => obj.Post.DateOccurred > obj.Login.DateOccurred)
.Join(user.LoginEvents, x => x.Login.User, y => y.User, (x, y) => new { Post = x.Post, Login = x.Login, LoginY = y })
//.Where(obj => obj.Post.DateOccurred < obj.LoginY.DateOccurred)
.Select(obj => new { IpAddress = obj.Login.IpAddress, Content = obj.Post.Content, DateOccurred = obj.Post.DateOccurred, NextLogin = obj.LoginY });
MagnusTheRed90 30 Newbie Poster
The following code is not working correctly. It is supposed to be associating an ip address of a user with a post's content, which in an online scenareo you know can be two different ip addresses. It is therefore showing exactly what was done with an account in the event of a password cracking scenareo. It is supposed to display what the hacker did while you were out. It is just a sample program, and if you could troubleshoot my linq that would be great. What it is doing now is not correctly taking into account the date and time of the next entry in the list.
/*Author: XXX
Purpose: To create a program that tracks the posts of disperate parties logging into an application in order to determine culpability.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DualPersonalitiesCulpability {
class Program {
static void Main(string[] args) {
List<Post> posts = new List<Post>();
User user = new User("Joe Schmoe");
DateTime dateOccurred = DateTime.Now - TimeSpan.FromDays(-4);
user.AddLoginEvent("192.168.1.1", DateTime.Now - TimeSpan.FromDays(-1));
Post post = new Post(user, "Something Good... ", dateOccurred.AddMinutes(15));
posts.Add(post);
dateOccurred = DateTime.Now - TimeSpan.FromDays(-3);
user.AddLoginEvent("192.168.1.2", dateOccurred);
post = new Post(user, "Something Bad... ", dateOccurred.AddMinutes(15));
posts.Add(post);
//dateOccurred = DateTime.Now - TimeSpan.FromDays(-2);
//user.AddLoginEvent("192.168.1.1", dateOccurred);
//post = new Post(user, "Something Good... ", dateOccurred.AddMinutes(15));
//posts.Add(post);
//dateOccurred = DateTime.Now - TimeSpan.FromDays(-1);
//user.AddLoginEvent("192.168.1.2", dateOccurred);
//post = new Post(user, "Something Bad... ", dateOccurred.AddMinutes(15));
//posts.Add(post);
//var ipAndDate = user.LoginEvents.Select(usr => new { IpAddress = usr.IpAddress, DateOccurred = usr.DateOccurred, Usr = usr });
posts …
MagnusTheRed90 30 Newbie Poster
I believe that I have the answer to my own question. Looks like not many of you do angular js. The most profound thing I learned from this is that we are using multiple views in all the online examples, with one view, "the home view" being the initial drop page. This was really really important to figuring anything out. I am not completely done with my application, but I think this is an appropriate response, and my code compiles. I am also doing a uib modal, so ignore anything that is ui bootstrap.
angular.module('UnitModule', [
'UnitModule.UnitsController',
'UnitModule.AddWeaponController',
])
.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider.when('/', {
templateUrl: '/Units',
controller: 'Units',
});
$routeProvider.when('/AddWeapon/:unitId', {
templateUrl: '/Home/AddWeapon',
controller: 'AddWeapon',
});
$routeProvider.otherwise({
redirectTo: '/'
});
}]);
//Units controller
angular.module('UnitModule.UnitsController', ['ngRoute', 'ui.bootstrap'])
.controller('Units', function ($scope, $http, $routeParams, $q, $rootScope, $route, $uibModal) {
});
angular.module('UnitModule.AddWeaponController', ['ngRoute'])
.controller('AddWeapon', function ($scope, $http, $routeParams) {
$scope.unitId = $routeParams.unitId;
}//end class
//additionally you need an AddWeapon() method that returns a partial view
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TroopTransportGeneticAlgorithim.Repositories;
using TroopTransportGeneticAlgorithim.Models;
namespace TroopTransportOptimizer.Controllers {
public class UnitsController : Controller {
// GET: Units
public ActionResult Index() {
return View();
}//end method
public ActionResult AddWeapon() {
return PartialView();
}
}//end class
}//end namespace
//additionally you need at least two files/views under the Units folder
-index.cshtml
-AddWeapon.cshtml
MagnusTheRed90 30 Newbie Poster
The following code fixes the problem.
/// <summary>
/// Copies file to archival directory.
/// </summary>
/// <param name="fileName"></param>
public void CopyFile(String fileName) {
var stream = SrcRepo.GetById(fileName);
//plus 1 for preceding slash character in the path
String pathInsideArchive = fileName.Substring(FileSystemPath.Length + 1, fileName.Length - FileSystemPath.Length - 1);
DestRepo.Insert(pathInsideArchive, stream);
}//end method
/// <summary>
/// Insert file into existing archive file.
/// </summary>
/// <param name="fullPath"></param>
/// <param name="stream"></param>
public void InsertIntoFile(String fullPath, Stream stream) {
using (var fs = new FileStream(FullArchivalPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) {
using (var zipFile = new ZipFile(fs)) {
zipFile.BeginUpdate();
var dataSource = new CustomDataSource();
dataSource.SetStream(stream);
zipFile.Add(dataSource, fullPath);
zipFile.CommitUpdate();
zipFile.Close();
}
}
}//end method
/// <summary>
/// A do nothing class necessary for some functionality in the prior code.
/// </summary>
public class CustomDataSource : IStaticDataSource {
private Stream stream;
public CustomDataSource() { }
public CustomDataSource(Stream stream) {
SetStream(stream);
}
public Stream GetSource() {
return stream;
}
public void SetStream(Stream stream) {
this.stream = stream;
this.stream.Position = 0;
}
}//end class
MagnusTheRed90 30 Newbie Poster
I am trying to pass url parameters to an angular js page for page setup. I was wondering if anyone could tell me whether I am missing something from these two code samples. The following is some code from a game related program that I am writing. The $routeProvider parameter is providing me null variables.
/*Author: XXX
Purpose: controller for units aggregate root single page application. */
//units
var units = [];
//declare the module/application
var app = angular.module('UnitModule', ['ngRoute', 'ui.bootstrap']);
app.config(function ($routeProvider) {
$routeProvider.when('/AddWeapon/:unitId', {
templateUrl: 'AddWeapon/index.cshtml',
controller: 'AddWeaponController'
})
});
//declare the controller
app.controller("AddWeaponController", ['$scope', '$routeParams', function ($scope, $routeParams, $http, $q, $rootScope, $route) {
$scope.ApiControllerName = "Units";
$scope.ApiDomainName = "http://localhost";
$scope.ApiPortNumber = "59971";
$scope.ApiRoutePrefix = "api";
$scope.oneAtATime = true;
$scope.unit = {
Weapons: []
};
$scope.Weapon = {
WeaponName: "",
Type: "",
ArmourPenetration: 0,
Abilities: "-"
}
$scope.GetUrl = function (funcName, args) {
var url = $scope.ApiDomainName + ":"
+ $scope.ApiPortNumber
+ "/" + $scope.ApiRoutePrefix + "/"
+ $scope.ApiControllerName;
if (funcName)
url += "/" + funcName;
if (!Array.isArray(args))
throw "Argument is not an array... ";
//build argument list
if (args && args.length > 0)
angular.forEach(args, function (value, key) {
url += "/" + value;
});
return url;
}//end method
$scope.GetSelfUrl = function (htmlFile) {
var domainName = 'http://localhost';
var portNum = 49752;
var url = domainName + ":"
+ portNum;
if (!htmlFile.startsWith("/"))
url += "/";
url += htmlFile;
return url;
}//end method
$scope.Get = function (id) {
var url = $scope.GetUrl('', [id]);
return $http.get(url);
}//end method
$scope.Post …
MagnusTheRed90 30 Newbie Poster
I have a class which is sort of like a repository, and every time I write to the zip archive using this command, the prior activity is overwritten.
/// <summary>
/// Insert file into existing archive file.
/// </summary>
/// <param name="fullPath"></param>
/// <param name="stream"></param>
public void InsertIntoFile(String fullPath, Stream stream) {
using (var fs = new FileStream(FullArchivalPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) {
using (var zipOutput = new ZipOutputStream(fs)) {
zipOutput.SetLevel(9);
if (fullPath.Contains(@"\")) {
ZipEntry zipDir = new ZipEntry(Path.GetDirectoryName(fullPath) + @"\");
zipDir.DateTime = DateTime.Now;
zipOutput.PutNextEntry(zipDir);
}
ZipEntry zipEntry = new ZipEntry(fullPath);
zipEntry.DateTime = DateTime.Now;
zipOutput.PutNextEntry(zipEntry);
var length = (int)stream.Length;
byte[] content = new byte[length];
stream.Read(content, 0, length);
zipOutput.Write(content, 0, length);
zipOutput.CloseEntry();
zipOutput.Finish();
zipOutput.Close();
}
}
}//end method
MagnusTheRed90 30 Newbie Poster
Sorry, the problem is that the code is not posting the model on reply. It is not filling the text box when I click the generate password button. The model does not post.
MagnusTheRed90 30 Newbie Poster
I have a problem where my text boxes are not being populated with existing data. I have two submit buttons, but the problem appears to happen when I call; return View("Index", siteInfo);. Here is my code;
// GET: NewEntry
public ActionResult Index() {
return View();
}
/// <summary>
/// Generate a password.
/// </summary>
/// <param name="siteInfo"></param>
/// <returns></returns>
[HttpPost]
[MultipleButton(Name = "action", Argument = "GeneratePassword")]
public ActionResult GeneratePassword(SiteInfo siteInfo) {
//generate the password
PasswordGenerator generator = new PasswordGenerator(NumLetters, NumNumbers, NumSymbols);
siteInfo.Password = generator.GeneratePassorwd();
//redirect to current view with errored object
return View("Index", siteInfo);
}//end method
@using PasswordManager.Models;
@using PasswordManager.Repositories;
@model PasswordManager.Models.SiteInfo
@{
ViewBag.Title = "New Entry";
}
<h2>New Entry</h2>
@Scripts.Render("~/Scripts/jquery-ui-1.10.2.min.js")
<link href='@Url.Content("~/Content/themes/base/jquery-ui.css")' rel="stylesheet" type="text/css" />
<div class="jumbotron">
<h1>New Entry</h1>
<p class="lead">Add password information to the password manager. </p>
</div>
<div class="container">
<!-- Left side. -->
<div class="col-md-2">
<ul id="links">
<li><a href="@Url.Action("Index", "Home")">Home page</a></li>
</ul>
</div>
@using (Html.BeginForm()) {
<!-- Right Side. -->
<div class="col-md-10">
<h2>New Entry</h2>
<!-- Site Name. -->
<div class="form-group">
<label class="control-label col-md-4" for="txtSiteName">Site Name:</label>
<div class="col-md-8">
@Html.TextBoxFor(model => model.SiteName, new { @class = "form-control", id = "txtSiteName" })
</div>
</div>
<!-- Login Url. -->
<div class="form-group">
<label class="control-label col-md-4" for="txtLoginUrl">Login Url:</label>
<div class="col-md-8">
@Html.TextBoxFor(model => model.LoginUrl, new { @class = "form-control", id = "txtLoginUrl" })
</div>
</div>
<!-- Password. -->
<div class="form-group">
<label class="control-label col-md-4" for="txtPassword">Password:</label>
<div class="col-md-8">
@Html.TextBoxFor(model => model.Password, new { @class = "form-control", id = "txtPassword" })
</div>
</div>
<button id="btnGeneratePassword" name="action:GeneratePassword" type="submit" class="btn btn-primary" value="GeneratePassword">Generate Password</button>
<!-- Description. -->
<div …
MagnusTheRed90 30 Newbie Poster
Does anybody know a good way to break a screen up into multiple sections for filling out lengthy multi section data? I would like something that I can break data inputs up into sections and move onto the next section when I finish filliing out a section prior, sequentially. What I know about is the accordion object in ui bootstrap, and that could work, but I thought I heard of something early in my career that was something pronounced like "flow". I am trying to make a page for an aggregate root. This will be on an html page. I need to proceed from one section to the next sequentially filling out data of an aggregate root object.
MagnusTheRed90 30 Newbie Poster
If you answer, great, but I'm dropping oracle support. Will be going mssql.
rproffitt commented: For many reasons I keep on keeping on with MySQL. +15
MagnusTheRed90 30 Newbie Poster
I am crafting a code generator for something, and I have encountered some things that I do not know yet. Excuse the scambled eggs in this code, but could you please tell me what a job is, and how to get it to run a stored procedure for me? I am trying to run a cron job which will run a loader application every n days.
<#@ parameter type="System.String" name="LoadName" #> <#@ parameter type="System.String" name="LoadTime" #> <#@ parameter type="System.String" name="SchemaName" #> <#
//generate header information
String description = "Schedule a cron job for the Loader to run periodically. ";
PLSQLHeader header = new PLSQLHeader(description, "INITIAL CODE");
#> <#= header.Draw() #>CREATE PROCEDURE <#= SchemaName #>.ScheduleJob() AS
BEGIN
USE msdb;
EXEC dbo.sp_add_job
@job_name = N'<#= loadName #>';
EXEC dbo.sp_add_schedule
@schedule_name = N'LoaderJobs',
@freq_type = 4,
@freq_interval = 1,
@active_start_time = <#= loadTime #>;
EXEC sp_attach_schedule
@job_name = N'<#= loadName #>',
@schedule_name = N'RunOnce';
EXEC dbo.sp_add_jobserver
@job_name = N'<#= loadName #>';
END;
GO
MagnusTheRed90 30 Newbie Poster
I was hoping to keep this open as an ongoing discussion.
MagnusTheRed90 30 Newbie Poster
I need a simple external table definition for preforming loads from FIXED WIDTH files. I don't remember how to do External tables in oracle. This would be a Fixed width, not CSV. I am creating a generator and I need the external table definition.
MagnusTheRed90 30 Newbie Poster
I have to get an instance of Oracle XE running on my laptop. This is so I can test a plsql package I have been working on at my house. Currently out of the job. I seem to remember when I did this the last time I had to configure the tnsnames.ora and listener.ora files correctly. I would like everything to be as simple as possible. Ex, everything should be named XE or something. I can't even find the listener.ora file actually.
Need a brief walk through over the tnsnames.ora file and the listener.ora files.
MagnusTheRed90 30 Newbie Poster
Good observation. Please others post good business problems, even if "user stories" that newbies should be thinking of. Thanks.
MagnusTheRed90 30 Newbie Poster
So, I am a post grad student in the software development field, and I am not working at the moment, but I have some questions on Business Rules, User Stories, etc. So I was wondering if perhaps we could open up a discussion here on some of the common business problems that programmers typically run into in their fields, and what sorts of user stories could be useful for an entry level programmer to pursue in their development career. I have an example;
Recently I rode in a cab. While in this cab we had to wait for a truant passenger who habitually did not participate in the trips. From this I derived a user story, where the cabbies could use a truancy histogram such that they could rate customers on attendance and change the color of pins on their gps devices. The User story is that there are habitually truant passengers. The solution is a truancy histogram.
Specifically I just want some good ideas on User Stories and Buisiness Rules that typically come up and you can post here some of your observations.
/*
DELETE FROM ATTENDANCE
WHERE DATE_EVENT < date() - 30
*/
//create database tables initialize database
var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(User).Assembly);
new SchemaExport(cfg).Execute(true, true, false);
//create user
User user = new User();
user.UserName = "Cameron Block";
//create attendance history
user.Attendance = new List<Attendance>();
Random rand = new Random((int)DateTime.Now.Ticks);
for (int i = 0; i < 2; i++) {
bool isTruant …