Easy-Secure is a digital certificate-issuing authority (CA) - NSC Information Technology - Question 2 - 2017 - Paper 1
Question 2
Easy-Secure is a digital certificate-issuing authority (CA). Online traders can apply for a digital certificate. You need a program to test the validity of existing ... show full transcript
Worked Solution & Example Answer:Easy-Secure is a digital certificate-issuing authority (CA) - NSC Information Technology - Question 2 - 2017 - Paper 1
Step 1
Write code for a constructor method that will receive the name of the certificate holder, the expiry date, the security code and the issue number as parameters.
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Write active and a method called increasesIssueNr that will increment the issue number by 1.
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
public void increasesIssueNr() {
issueNr += 1;
}
Step 3
Write code for a method called resetExpiryDate that will reset the expiry date attribute of the digital certificate to the new expiry date of the digital certificate as set by the system date. Ensure that it is valid FOR ONE year.
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
public void resetExpiryDate() {
String newExpiry = $SysDate;
// Add 1 year to the current expiry date logic here
expiryDate = newExpiry;
}
Step 4
Write code to complete the method called hasExpired that will determine whether the expiry date attribute has expired by comparing it to the system date.
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
public boolean hasExpired() {
// Compare expiryDate with current date logic here
return expiryDate.compareTo($SysDate) < 0;
}
Step 5
Write code to complete the method called generateSecurityCode to compile a security code using randomly selected hexadecimal values.
97%
117 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
public String generateSecurityCode() {
StringBuilder securityCode = new StringBuilder();
// Generate 10 random hex characters
for(int i = 0; i < 10; i++) {
securityCode.append("0123456789ABCDEF".charAt((int)(Math.random() * 16)));
}
// Insert 4 colons
for(int i = 0; i < 3; i++) {
securityCode.insert((i+1)*3, ':'); // Adds colons
}
return securityCode.toString();
}
Step 6
Write code to complete the given toString method that will return a string with attributes in the following format:
97%
121 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Display a suitable message if the digital certificate has NOT expired.
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
if(!digCert.hasExpired()) {
System.out.println("The digital certificate is valid.");
} else {
System.out.println("The digital certificate has expired.");
}